fix File::Spec->abs2rel() to return absolute $path more often for VMS
[p5sagit/p5-mst-13.2.git] / lib / File / Path.pm
index 3560a97..7881b6b 100644 (file)
@@ -40,6 +40,15 @@ the numeric mode to use when creating the directories
 It returns a list of all directories (including intermediates, determined
 using the Unix '/' separator) created.
 
+If a system error prevents a directory from being created, then the
+C<mkpath> function throws a fatal error with C<Carp::croak>. This error
+can be trapped with an C<eval> block:
+
+  eval { mkpath($dir) };
+  if ($@) {
+    print "Couldn't create $dir: $@";
+  }
+
 Similarly, the C<rmtree> function provides a convenient way to delete a
 subtree from the directory structure, much like the Unix command C<rm -r>.
 C<rmtree> takes three arguments:
@@ -81,9 +90,21 @@ were not deleted may be left with permissions reset to allow world
 read and write access.  Note also that the occurrence of errors in
 rmtree can be determined I<only> by trapping diagnostic messages
 using C<$SIG{__WARN__}>; it is not apparent from the return value.
-Therefore, you must be extremely careful about using C<rmtree($foo,$bar,0>
+Therefore, you must be extremely careful about using C<rmtree($foo,$bar,0)>
 in situations where security is an issue.
 
+=head1 DIAGNOSTICS
+
+=over 4
+
+=item *
+
+On Windows, if C<mkpath> gives you the warning: B<No such file or
+directory>, this may mean that you've exceeded your filesystem's
+maximum path length.
+
+=back
+
 =head1 AUTHORS
 
 Tim Bunce <F<Tim.Bunce@ig.co.uk>> and
@@ -98,7 +119,7 @@ use Exporter ();
 use strict;
 use warnings;
 
-our $VERSION = "1.0405";
+our $VERSION = "1.06";
 our @ISA = qw( Exporter );
 our @EXPORT = qw( mkpath rmtree );
 
@@ -180,7 +201,13 @@ sub rmtree {
                unless $safe;
 
            if (opendir my $d, $root) {
-               @files = readdir $d;
+               no strict 'refs';
+               if (!defined ${"\cTAINT"} or ${"\cTAINT"}) {
+                   # Blindly untaint dir names
+                   @files = map { /^(.*)$/s ; $1 } readdir $d;
+               } else {
+                   @files = readdir $d;
+               }
                closedir $d;
            }
            else {