line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IO::AIO::Util; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
140549
|
use strict; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
58
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
55
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use Exporter qw(import); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
56
|
|
7
|
2
|
|
|
2
|
|
823
|
use IO::AIO 2; |
|
2
|
|
|
|
|
5792
|
|
|
2
|
|
|
|
|
372
|
|
8
|
2
|
|
|
|
|
144
|
use File::Spec::Functions qw( |
9
|
|
|
|
|
|
|
canonpath catpath catdir splitdir splitpath updir |
10
|
2
|
|
|
2
|
|
937
|
); |
|
2
|
|
|
|
|
1704
|
|
11
|
2
|
|
|
2
|
|
1082
|
use POSIX (); |
|
2
|
|
|
|
|
12436
|
|
|
2
|
|
|
|
|
690
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
14
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw(aio_mkpath aio_mktree); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub aio_mkpath { |
19
|
4
|
|
|
4
|
1
|
5235
|
my ($path, $mode, $cb) = @_; |
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
|
|
11
|
my $pri = aioreq_pri; |
22
|
4
|
|
|
|
|
36
|
my $grp = aio_group $cb; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Default is success. |
25
|
4
|
|
|
|
|
22
|
local $!; |
26
|
4
|
|
|
|
|
16
|
$grp->result(0); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Clean up the path. |
29
|
4
|
|
|
|
|
12
|
$path = canonpath($path); |
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
|
|
14
|
my ($vol, $dir, undef) = splitpath($path, 1); |
32
|
4
|
|
|
|
|
36
|
my @dir = splitdir($dir); |
33
|
4
|
|
|
|
|
25
|
my $idx = 0; |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
7
|
my $sub; $sub = sub { |
36
|
17
|
|
|
17
|
|
49
|
for (; $idx < @dir; $idx++) { |
37
|
|
|
|
|
|
|
# Root and parent directories are assumed to always exist. |
38
|
19
|
100
|
66
|
|
|
83
|
last if '' ne $dir[$idx] and updir ne $dir[$idx]; |
39
|
|
|
|
|
|
|
} |
40
|
17
|
100
|
|
|
|
48
|
return $grp if @dir <= $idx; |
41
|
|
|
|
|
|
|
|
42
|
15
|
|
|
|
|
93
|
my $path = catpath($vol, catdir(@dir[0 .. $idx]), ''); |
43
|
|
|
|
|
|
|
|
44
|
15
|
|
|
|
|
129
|
aioreq_pri $pri; |
45
|
|
|
|
|
|
|
add $grp aio_mkdir $path, $mode, sub { |
46
|
15
|
100
|
50
|
|
|
1334
|
$idx++ and return $sub->() unless $_[0]; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Ignore "file exists" errors unless it is the last component, |
49
|
|
|
|
|
|
|
# then stat it to ensure it is a directory. This matches |
50
|
|
|
|
|
|
|
# the behaviour of `mkdir -p` from GNU coreutils. |
51
|
13
|
100
|
50
|
|
|
161
|
$idx++ and return $sub->() if &POSIX::EEXIST == $! |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
52
|
|
|
|
|
|
|
and not ($idx == $#dir and not -d $path); |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
10
|
$grp->cancel_subs; |
55
|
2
|
|
|
|
|
9
|
$grp->errno($!); |
56
|
2
|
|
|
|
|
8
|
$grp->result($_[0]); |
57
|
2
|
|
|
|
|
7
|
return $grp; |
58
|
15
|
|
|
|
|
711
|
}; |
59
|
4
|
|
|
|
|
20
|
}; |
60
|
|
|
|
|
|
|
|
61
|
4
|
|
|
|
|
16
|
return $sub->(); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
*aio_mktree = \&aio_mkpath; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |