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