[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

concurrency issue with File/Path.pm in rmtree



I'm not sure where to start with this other than an email to the authors,
but if two independent rmtree's are done within the same directory tree, one
of the scripts could abort with messages similar to the following:

Can't read any.directory: No such file or directory at /clientdir/ers.pl
line 1222
Can't call method "read" on an undefined value at
/usr/local/lib/perl/lib/perl5/5.00503/File/Path.pm line 171.

DirHandle->new can return undef if the directory has disappeared.    (I
suspect that the first message is the carp or'ed with the new).
The second message results when the undef'ed $d is used.

    foreach $root (@{$roots}) {
        $root =~ s#/$##;
        (undef, undef, my $rp) = lstat $root or next;
        $rp &= 07777;   # don't forget setuid, setgid, sticky bits
        if ( -d _ ) {
            # notabene: 0777 is for making readable in the first place,
            # it's also intended to change it to writable in case we have
            # to recurse in which case we are better than rm -rf for
            # subtrees with strange permissions
            chmod(0777, ($Is_VMS ? VMS::Filespec::fileify($root) : $root))
              or carp "Can't make directory $root read+writeable: $!"
                unless $safe;

            my $d = DirHandle->new($root)

              or carp "Can't read $root: $!";
<----------------------------- first message
            @files = $d->read;
<----------------------------- second message
            $d->close;

I wonder if the code might better read:

             my $d = DirHandle->new($root)
                or carp "Can't read $root: $!";
             if (defined($d)) {
                  @files = $d->read;
                  $d->close;
             } else {
                  @files = (); # could open, so empty the list
             }


[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]