/usr/share/perl5/File/Path/Tiny.pm is in libfile-path-tiny-perl 0.7-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.7;
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 ( $progressive, @parts ) = File::Spec->splitdir($path);
if ( !defined $progressive || $progressive eq '' ) {
$progressive = File::Spec->catdir( $progressive, shift(@parts) );
}
if ( !-d $progressive ) {
mkdir( $progressive, $mask ) or return;
}
for my $part (@parts) {
$progressive = File::Spec->catdir( $progressive, $part );
if ( !-d $progressive ) {
mkdir( $progressive, $mask ) 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 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 return;
}
else {
unlink $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;
|