=back
It returns a list of all directories (including intermediates, determined
-using the Unix '/' separator) created.
+using the Unix '/' separator) created. In scalar context it returns
+the number of directories 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
=back
-It returns the number of files successfully deleted. Symlinks are
-simply deleted and not followed.
+It returns the number of files, directories and symlinks successfully
+deleted. Symlinks are simply deleted and not followed.
B<NOTE:> There are race conditions internal to the implementation of
C<rmtree> making it unsafe to use on directory trees which may be
=cut
use 5.006;
-use Carp;
use File::Basename ();
use Exporter ();
use strict;
use warnings;
-our $VERSION = "1.07";
+our $VERSION = "1.08";
our @ISA = qw( Exporter );
our @EXPORT = qw( mkpath rmtree );
my $force_writeable = ($^O eq 'os2' || $^O eq 'dos' || $^O eq 'MSWin32' ||
$^O eq 'amigaos' || $^O eq 'MacOS' || $^O eq 'epoc');
+sub carp {
+ require Carp;
+ goto &Carp::carp;
+}
+
+sub croak {
+ require Carp;
+ goto &Carp::croak;
+}
+
sub mkpath {
my($paths, $verbose, $mode) = @_;
# $paths -- either a path string or ref to list of paths
if ($Is_VMS) {
next if $path eq '/';
$path = VMS::Filespec::unixify($path);
- if ($path =~ m:^(/[^/]+)/?\z:) {
- $path = $1.'/000000';
- }
}
next if -d $path;
my $parent = File::Basename::dirname($path);
unless (mkdir($path,$mode)) {
my $e = $!;
# allow for another process to have created it meanwhile
- croak "mkdir $path: $e" unless -d $path;
+ $! = $e, croak ("mkdir $path: $e") unless -d $path;
}
push(@created, $path);
}
$roots = [$roots] unless ref $roots;
}
else {
- carp "No root path(s) specified\n";
+ carp ("No root path(s) specified\n");
return 0;
}
# to recurse in which case we are better than rm -rf for
# subtrees with strange permissions
chmod($rp | 0700, ($Is_VMS ? VMS::Filespec::fileify($root) : $root))
- or carp "Can't make directory $root read+writeable: $!"
+ or carp ("Can't make directory $root read+writeable: $!")
unless $safe;
if (opendir my $d, $root) {
closedir $d;
}
else {
- carp "Can't read $root: $!";
+ carp ("Can't read $root: $!");
@files = ();
}
next;
}
chmod $rp | 0700, $root
- or carp "Can't make directory $root writeable: $!"
+ or carp ("Can't make directory $root writeable: $!")
if $force_writeable;
print "rmdir $root\n" if $verbose;
if (rmdir $root) {
++$count;
}
else {
- carp "Can't remove directory $root: $!";
+ carp ("Can't remove directory $root: $!");
chmod($rp, ($Is_VMS ? VMS::Filespec::fileify($root) : $root))
or carp("and can't restore permissions to "
. sprintf("0%o",$rp) . "\n");
next;
}
chmod $rp | 0600, $root
- or carp "Can't make file $root writeable: $!"
+ or carp ("Can't make file $root writeable: $!")
if $force_writeable;
print "unlink $root\n" if $verbose;
# delete all versions under VMS
for (;;) {
unless (unlink $root) {
- carp "Can't unlink file $root: $!";
+ carp ("Can't unlink file $root: $!");
if ($force_writeable) {
chmod $rp, $root
or carp("and can't restore permissions to "