add files and tweaks needed for MPE/iX port (via PM)
[p5sagit/p5-mst-13.2.git] / lib / File / Path.pm
index 419bd03..39f1ba1 100644 (file)
@@ -92,7 +92,7 @@ Charles Bailey <F<bailey@genetics.upenn.edu>>
 
 =head1 REVISION
 
-Current $VERSION is 1.03.
+Current $VERSION is 1.0401.
 
 =cut
 
@@ -103,7 +103,7 @@ use Exporter ();
 use strict;
 
 use vars qw( $VERSION @ISA @EXPORT );
-$VERSION = "1.03";
+$VERSION = "1.0401";
 @ISA = qw( Exporter );
 @EXPORT = qw( mkpath rmtree );
 
@@ -111,7 +111,7 @@ my $Is_VMS = $^O eq 'VMS';
 
 # These OSes complain if you want to remove a file that you have no
 # write permission to:
-my $force_writeable = ($^O eq 'os2' || $^O eq 'msdos' || $^O eq 'MSWin32'
+my $force_writeable = ($^O eq 'os2' || $^O eq 'dos' || $^O eq 'MSWin32'
                       || $^O eq 'amigaos');
 
 sub mkpath {
@@ -124,13 +124,20 @@ sub mkpath {
     $paths = [$paths] unless ref $paths;
     my(@created,$path);
     foreach $path (@$paths) {
+       $path .= '/' if $^O eq 'os2' and $path =~ /^\w:$/; # feature of CRT 
        next if -d $path;
        # Logic wants Unix paths, so go with the flow.
        $path = VMS::Filespec::unixify($path) if $Is_VMS;
        my $parent = File::Basename::dirname($path);
-       push(@created,mkpath($parent, $verbose, $mode)) unless (-d $parent);
+       # Allow for creation of new logical filesystems under VMS
+       if (not $Is_VMS or $parent !~ m:/[^/]+/000000/?:) {
+           push(@created,mkpath($parent, $verbose, $mode)) unless (-d $parent);
+       }
        print "mkdir $path\n" if $verbose;
-       mkdir($path,$mode) || croak "mkdir $path: $!";
+       unless (mkdir($path,$mode)) {
+           # allow for another process to have created it meanwhile
+           croak "mkdir $path: $!" unless -d $path;
+       }
        push(@created, $path);
     }
     @created;
@@ -147,13 +154,13 @@ sub rmtree {
     my($root);
     foreach $root (@{$roots}) {
        $root =~ s#/$##;
-       next unless -e $root;
-       if (not -l $root and -d _) {
+       (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
-           my $rp = (stat(_))[2] & 0777;  #Is this portable???
            chmod(0777, ($Is_VMS ? VMS::Filespec::fileify($root) : $root))
              or carp "Can't make directory $root read+writeable: $!"
                unless $safe;
@@ -194,24 +201,23 @@ sub rmtree {
                print "skipped $root\n" if $verbose;
                next;
            }
-           my $rp = (stat(_))[2] & 0777;  #Is this portable???
            chmod 0666, $root
              or carp "Can't make file $root writeable: $!"
                if $force_writeable;
            print "unlink $root\n" if $verbose;
            # delete all versions under VMS
-           while (-e $root || -l $root) {
-               if (unlink $root) {
-                   ++$count;
-               }
-               else {
+           for (;;) {
+               unless (unlink $root) {
                    carp "Can't unlink file $root: $!";
                    if ($force_writeable) {
                        chmod $rp, $root
                            or carp("and can't restore permissions to "
                                    . sprintf("0%o",$rp) . "\n");
                    }
+                   last;
                }
+               ++$count;
+               last unless $Is_VMS && lstat $root;
            }
        }
     }