[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Bug found in MacPerl 5.1.0



At 2:21 PM -0500 on 11/25/96, Frank J. Faubert, Jr. wrote:


}Hi,
}
}   I've found a bug in MacPerl 5.1.0 with the rmtree function in
}File::Path;  rmtree is still using "/" instead of ":".  To duplicate:
}
}Make a directory "moo"
}Put a file "moo.txt" in it.
}
}Use the following code:
}use File::Path;
}
}rmtree( "My Hard Drive:moo", 1, 0 );
}
}
}
}Please let me know of any workarounds/fixes.

File::Path is a a readable, editable text file sitting in your MacPerl lib
folder.  Understanding how library routines work, especially ones that are
giving you trouble, is a good way to learn some Perl.  So why not fix it
and make your changes available?

In thisk case, I'll give you some help.  Here, try this, it works in the
one test I've tried.  Replace the rmtree routine with this, and let us know
if you have any trouble with it.  Only two changes needed to be made.
Here's the test

use File::Path;

mkpath("Macintosh HD:moo",1,0);
open(OUT,">Macintosh HD:moo:moo.txt");
print OUT "moo\n";
close(OUT);
rmtree( "Macintosh HD:moo", 1, 0 );

and here's the revised rmtree:

sub rmtree {
    my($roots, $verbose, $safe) = @_;
    my(@files);
    my($count) = 0;
    $roots = [$roots] unless ref $roots;

    foreach $root (@{$roots}) {
      $root =~ s#:$##;
       if (not -l $root and -d _) {
           opendir(D,$root);
           ($root = VMS::Filespec::unixify($root)) =~ s#\.dir$## if $Is_VMS;
           @files = map("$root:$_", readdir(D));
           closedir(D);
           $count += rmtree(\@files,$verbose,$safe);
           if ($safe &&
               ($Is_VMS ? !&VMS::Filespec::candelete($root) : !-w $root)) {
               print "skipped $root\n" if $verbose;
               next;
           }
           print "rmdir $root\n" if $verbose;
           (rmdir $root && ++$count) or carp "Can't remove directory $root:
$!";
        }
        else {
           if ($safe &&
               ($Is_VMS ? !&VMS::Filespec::candelete($root) : !-w $root)) {
               print "skipped $root\n" if $verbose;
               next;
           }
           print "unlink $root\n" if $verbose;
           while (-e $root || -l $root) { # delete all versions under VMS
               (unlink($root) && ++$count)
                   or carp "Can't unlink file $root: $!";
           }
        }
    }

    $count;
}

}
}-Frank
}---------------------------------------------------------------------------
}    Frank J. Faubert, Jr.         |           Sane Solutions, LLC.
}  Chief Information Officer       |     INTERNET - INTRANETS - SOFTWARE
}      frank@sane.com              |   (800) 407-3570  http://www.sane.com
}---------------------------------------------------------------------------


--------
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693
Greenbelt, MD 20770
schinder@leprss.gsfc.nasa.gov