[Fusioninventory-devel] dubious 'fix'

Guillaume Rousse guillomovitch at gmail.com
Sat Apr 30 16:16:52 UTC 2011


commit f124ca1eff608b6a8dcc4ebb2cf1bc6b9e7a52d9
Author: Gonéri Le Bouder <goneri at rulezlan.org>
Date:   Thu Apr 28 16:43:28 2011 +0200

    fix the unknwon secion key filter

diff --git a/lib/FusionInventory/Agent/XML/Query/Inventory.pm
b/lib/FusionInventory/Agent/XML/Query/Inventory.pm
index 777e12e..3a38a34 100644
--- a/lib/FusionInventory/Agent/XML/Query/Inventory.pm
+++ b/lib/FusionInventory/Agent/XML/Query/Inventory.pm
@@ -90,11 +90,13 @@ sub addEntry {
     die "unknown section $section" unless $fields;

     my $newEntry;
-    foreach my $field (@$fields) {
-        next unless defined $entry->{$field};
+    foreach my $field (keys %$entry) {
+        if (!grep $_ eq $field, @$fields) {
+            $self->{logger}->debug("unknown field for $section: $field");
+            next;
+        }
         $newEntry->{$field} = getSanitizedString($entry->{$field});
     }
-

This doesn't "fix" anything, this just log items with unknown attributes
added to the inventory (which is indeed useful). But this also change
the semantic of the function, by allowing undefined values to slip in
(they were filtered out previously by the removed line), and this is
considerably slower, by traversing the full list of allowed attributes
for each attribute of each item added to the inventory...

The correct way to conduct this kind of repeated lookup is to use an
hash instead.
-- 
BOFH excuse #404:

Sysadmin accidentally destroyed pager with a large hammer.



More information about the Fusioninventory-devel mailing list