/usr/share/perl5/File/Path/Tiny.pm is in libfile-path-tiny-perl 0.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | package File::Path::Tiny;
use strict;
use warnings;
$File::Path::Tiny::VERSION = 0.8;
sub mk {
my ( $path, $mask ) = @_;
return 2 if -d $path;
if ( -e $path ) { $! = 20; return; }
$mask ||= '0777'; # Perl::Critic == Integer with leading zeros at ...
$mask = oct($mask) if substr( $mask, 0, 1 ) eq '0';
require File::Spec;
my ( $vol, $directories ) = File::Spec->splitpath( $path, 1 );
my @dirs = File::Spec->splitdir($directories);
my @list;
while ( my ($_dir) = shift @dirs ) {
last if not defined $_dir;
push @list, $_dir;
next if ( $_dir eq '' );
my $progressive = File::Spec->catpath( $vol, File::Spec->catdir(@list), '' );
if ( !-d $progressive ) {
mkdir( $progressive, $mask ) or -d $progressive or return;
}
}
return 1 if -d $path;
return;
}
sub rm {
my ($path) = @_;
if ( -e $path && !-d $path ) { $! = 20; return; }
return 2 if !-d $path;
empty_dir($path) or return;
rmdir($path) or !-e $path or return;
return 1;
}
sub empty_dir {
my ($path) = @_;
if ( -e $path && !-d $path ) { $! = 20; return; }
opendir( DIR, $path ) or return;
my @contents = grep { $_ ne '.' && $_ ne '..' } readdir(DIR);
closedir DIR;
require File::Spec if @contents;
for my $thing (@contents) {
my $long = File::Spec->catdir( $path, $thing );
if ( !-l $long && -d $long ) {
rm($long) or !-e $long or return;
}
else {
unlink $long or !-e $long or return;
}
}
return 1;
}
sub mk_parent {
my ( $path, $mode ) = @_;
$path =~ s{/+$}{};
require File::Spec;
my ( $v, $d, $f ) = File::Spec->splitpath( $path, 1 );
my @p = File::Spec->splitdir($d);
# pop() is probably cheaper here, benchmark? $d = File::Spec->catdir(@p[0--$#p-1]);
pop @p;
$d = File::Spec->catdir(@p);
my $parent = File::Spec->catpath( $v, $d, $f );
return mk( $parent, $mode );
}
1;
|