Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injector skips directories one or two characters long #29

Open
jagarsoft opened this issue Feb 24, 2022 · 4 comments
Open

Injector skips directories one or two characters long #29

jagarsoft opened this issue Feb 24, 2022 · 4 comments
Labels
bug Something isn't working c:agent-perl (<3.0) Related to the agent writen in perl, so before and version 2.6

Comments

@jagarsoft
Copy link

When I run Injector script in order to sent them to a server, it reads from computer/ directory what has a set of directories based in first digit of XML file, like this:
computer/0/1.xml
computer/0/2.xml
...
computer/1/10.xml
computer/1/11.xml
...
computer/2/20.xml
computer/2/21.xml
etc

However, directories from 0 to 99 are skiped.

@jagarsoft
Copy link
Author

jagarsoft commented Feb 24, 2022

The problem was detected in line that skips . and .. entries of the root directory in -d flag

@jagarsoft
Copy link
Author

Where it says:

next if $file =~ /^..?$/ ;

must say:

next if $file =~ /^\.\.?$/ ;

That's all folks! ;-)

g-bougard referenced this issue in glpi-project/glpi-agent Feb 24, 2022
Backport of fix proposed in fusioninventory/fusioninventory-agent#1000
@jagarsoft
Copy link
Author

jagarsoft commented Feb 24, 2022

This can be reproduced like this:

mkdir computer
mkdir computer\0
mkdir computer\1
mkdir computer\2
echo 01.xml > computer\0\01.xml
echo 02.xml > computer\0\02.xml
echo 10.xml > computer\1\10.xml
echo 11.xml > computer\1\11.xml
echo 20.xml > computer\2\20.xml
echo 21.xml > computer\2\21.xml
mkdir computer\100
echo 100.xml > computer\100\100.xml
echo 101.xml > computer\100\101.xml

Run Injector:

perl.exe fusioninventory-injector -v -R -d computer -u http://localhost

Outputs:

In computer
computer/.
computer/..
computer/0
computer/1
computer/100
. and .. skiped
It's a DIR c:/computer/100
In computer/100
computer/100/.
computer/100/..
computer/100/100.xml
. and .. skipped
It's a FILE c:/computer/100/100.xml
Loading c:/computer/100/100.xml...ERROR: 500 Can't connect to localhost:80
Next DIR
computer/100/101.xml
. and .. skipped
It's a FILE c:/computer/100/101.xml
Loading c:/computer/100/101.xml...ERROR: 500 Can't connect to localhost:80
Next DIR
Next DIR
computer/2
These elements were not sent:
c:/computer/100/100.xml
c:/computer/100/101.xml

@jagarsoft
Copy link
Author

jagarsoft commented Feb 24, 2022

With this warns ;-)

sub loaddirectory {
    my ($directory) = @_;
warn "In $directory\n";
    die "directory $directory does not exist\n" unless -d $directory;
    die "directory $directory is not readable\n" unless -r $directory;

    opendir (my $handle, $directory)
        or die "can't open directory $directory: $ERRNO\n";
    foreach my $file (readdir($handle)) {
warn "$directory/$file\n";
        next if $file =~ /^\.\.?$/ ;
warn ". and .. skipped\n";
        if (-d "$directory/$file") {
warn "It's a DIR $directory/$file\n";
            loaddirectory("$directory/$file") if ($options->{recursive});
        } else {
warn "It's a FILE $directory/$file\n";
            loadfile("$directory/$file") if $file =~ /\.(?:ocs|xml)$/;
        }
warn "Next DIR\n";
    }
    closedir $handle;
}

@ddurieux ddurieux transferred this issue from fusioninventory/fusioninventory-agent Sep 3, 2024
@ddurieux ddurieux added bug Something isn't working c:agent-perl (<3.0) Related to the agent writen in perl, so before and version 2.6 labels Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working c:agent-perl (<3.0) Related to the agent writen in perl, so before and version 2.6
Projects
None yet
Development

No branches or pull requests

2 participants