line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Filesys::Virtual::Async::Plain; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
89154
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
100
|
|
4
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
88
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
11
|
use Filesys::Virtual::Async; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
45
|
|
9
|
2
|
|
|
2
|
|
11
|
use base qw( Filesys::Virtual::Async ); |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
214
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#use IO::AIO 2; |
12
|
2
|
|
|
2
|
|
12
|
use IO::AIO; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
6291
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
1
|
|
|
1
|
1
|
14
|
my $class = shift; |
16
|
1
|
|
|
|
|
11
|
my $self = $class->SUPER::new( @_ ); |
17
|
1
|
|
50
|
|
|
18
|
$self->{aio_max_group} ||= 4; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
3
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub dirlist { |
23
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $path, $withstat, $callback ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return $self->readdir( $path, sub { |
26
|
0
|
|
|
0
|
|
0
|
my $fl = shift; |
27
|
0
|
0
|
|
|
|
0
|
$fl = [ map { [ $_ ] } @$fl ] if ( ref $fl ); |
|
0
|
|
|
|
|
0
|
|
28
|
0
|
|
|
|
|
0
|
$callback->( $fl ); |
29
|
0
|
0
|
|
|
|
0
|
} ) unless ( $withstat ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$self->readdir( $path, sub { |
32
|
0
|
|
|
0
|
|
0
|
my $list = shift; |
33
|
0
|
0
|
|
|
|
0
|
return $callback->() unless ( $list ); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
my $root = $self->_path_from_root( $path ); |
36
|
0
|
|
|
|
|
0
|
my $files = []; |
37
|
0
|
|
|
|
|
0
|
for my $i ( 0 .. $#{$list} ) { |
|
0
|
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
# file path, index |
39
|
0
|
|
|
|
|
0
|
$files->[ $i ] = [ $root.'/'.$list->[ $i ], $i ]; |
40
|
0
|
|
|
|
|
0
|
$list->[ $i ] = [ $list->[ $i ] ]; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
my $grp = aio_group( $callback ); |
44
|
|
|
|
|
|
|
# pass $list to the callback |
45
|
0
|
|
|
|
|
0
|
$grp->result( $list ); |
46
|
0
|
|
|
|
|
0
|
limit $grp $self->{aio_max_group}; |
47
|
|
|
|
|
|
|
# add files |
48
|
|
|
|
|
|
|
feed $grp sub { |
49
|
0
|
0
|
|
|
|
0
|
my $file = pop @$files or return; |
50
|
|
|
|
|
|
|
add $grp aio_stat $file->[ 0 ], sub { |
51
|
0
|
0
|
|
|
|
0
|
$_[ 0 ] and return; |
52
|
0
|
|
|
|
|
0
|
$list->[ $file->[ 1 ] ]->[ 1 ] = $_[ 1 ]; |
53
|
0
|
|
|
|
|
0
|
}; |
54
|
0
|
|
|
|
|
0
|
}; |
55
|
0
|
|
|
|
|
0
|
} ); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub open { |
61
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
aio_open( $self->_path_from_root( shift ), $_[ 0 ], $_[ 1 ], $_[ 2 ] ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub close { |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
0
|
1
|
0
|
aio_close( $_[ 1 ], $_[ 2 ] ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# don't email me bitching about how this is done. It had to be done this way due to the prototype |
72
|
|
|
|
|
|
|
# on IO::AIO functions. If you have an alternative, enlighten me. |
73
|
|
|
|
|
|
|
sub read { |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
1
|
0
|
aio_read( $_[ 1 ], $_[ 2 ], $_[ 3 ], $_[ 4 ], $_[ 5 ], $_[ 6 ] ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub write { |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
0
|
1
|
0
|
aio_write( $_[ 1 ], $_[ 2 ], $_[ 3 ], $_[ 4 ], $_[ 5 ], $_[ 6 ] ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub sendfile { |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
0
|
1
|
0
|
aio_sendfile( $_[ 1 ], $_[ 2 ], $_[ 3 ], $_[ 4 ], $_[ 5 ] ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub readahead { |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
0
|
1
|
0
|
aio_readahead( $_[ 1 ], $_[ 2 ], $_[ 3 ], $_[ 4 ] ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub stat { |
94
|
1
|
|
|
1
|
1
|
618
|
my ( $self, $file, $callback ) = @_; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# TODO reftype |
97
|
|
|
|
|
|
|
# TODO stuff _ with stat cache |
98
|
1
|
50
|
|
1
|
|
505
|
return aio_stat( $self->_path_from_root( $file ), sub { $callback->( -e _ ? [ (CORE::stat( _ )) ] : undef ); } ) |
99
|
1
|
50
|
|
|
|
7
|
unless ( ref( $file ) eq 'ARRAY' ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# multi-stat |
102
|
0
|
|
|
|
|
|
my $list = []; |
103
|
0
|
0
|
|
|
|
|
return $callback->( $list ) unless ( @$file ); |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $tostat = []; |
106
|
0
|
|
|
|
|
|
foreach my $i ( 0 .. $#{$file} ) { |
|
0
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# file path, index |
108
|
0
|
|
|
|
|
|
$tostat->[ $i ] = [ $self->_path_from_root( $file->[ $i ] ), $i ]; |
109
|
0
|
|
|
|
|
|
$list->[ $i ] = [ $file->[ $i ] ]; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $grp = aio_group( $callback ); |
113
|
|
|
|
|
|
|
# pass $list to the callback |
114
|
0
|
|
|
|
|
|
$grp->result( $list ); |
115
|
0
|
|
|
|
|
|
limit $grp $self->{aio_max_group}; |
116
|
|
|
|
|
|
|
# add files |
117
|
|
|
|
|
|
|
feed $grp sub { |
118
|
0
|
0
|
|
0
|
|
|
my $f = pop @$tostat or return; |
119
|
|
|
|
|
|
|
add $grp aio_stat $f->[ 0 ], sub { |
120
|
0
|
0
|
|
|
|
|
$_[ 0 ] and return; |
121
|
|
|
|
|
|
|
# list[ idx ] = [ path, stat ] |
122
|
0
|
|
|
|
|
|
$list->[ $f->[ 1 ] ]->[ 1 ] = [ (CORE::stat( _ )) ]; |
123
|
0
|
|
|
|
|
|
}; |
124
|
0
|
|
|
|
|
|
}; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
return; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub lstat { |
130
|
0
|
|
|
0
|
1
|
|
my ( $fh, $callback ) = @_; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
0
|
|
|
aio_lstat( $fh, sub { $callback->( [ (CORE::stat( _ )) ] ) } ); |
|
0
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub utime { |
136
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
aio_utime( $self->_path_from_root( shift ), $_[ 0 ], $_[ 1 ], $_[ 2 ] ); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub chown { |
142
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
aio_chown( $self->_path_from_root( shift ), $_[ 0 ], $_[ 1 ], $_[ 2 ] ); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub truncate { |
148
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
aio_truncate( $self->_path_from_root( shift ), $_[ 0 ], $_[ 1 ] ); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub chmod { |
154
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
aio_chmod( $self->_path_from_root( shift ), $_[ 0 ], $_[ 1 ] ); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub unlink { |
160
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
aio_unlink( $self->_path_from_root( shift ), $_[ 0 ] ); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub mknod { |
166
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
aio_mknod( $self->_path_from_root( shift ), $_[ 0 ], $_[ 1 ], $_[ 2 ] ); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub link { |
172
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
aio_link( $self->_path_from_root( shift ), $self->_path_from_root( shift ), $_[ 0 ] ); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub symlink { |
178
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
aio_symlink( $self->_path_from_root( shift ), $self->_path_from_root( shift ), $_[ 0 ] ); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub readlink { |
184
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
aio_readlink( $self->_path_from_root( shift ), $_[ 0 ] ); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub rename { |
190
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
191
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
aio_rename( $self->_path_from_root( shift ), $self->_path_from_root( shift ), $_[ 0 ] ); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub mkdir { |
196
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
aio_mkdir( $self->_path_from_root( shift ), $_[ 0 ], $_[ 1 ] ); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub rmdir { |
202
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
aio_rmdir( $self->_path_from_root( shift ), $_[ 0 ] ); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub readdir { |
208
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
aio_readdir( $self->_path_from_root( shift ), $_[ 0 ] ); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub load { |
214
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
|
aio_load( $self->_path_from_root( shift ), $_[ 0 ], $_[ 1 ] ); |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub copy { |
220
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
my $src = $self->_path_from_root( shift ); |
223
|
0
|
|
|
|
|
|
my $dest = $self->_path_from_root( shift ); |
224
|
|
|
|
|
|
|
# aio won't take an ending slash |
225
|
0
|
|
|
|
|
|
$dest =~ s/\/$//; |
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
aio_copy( $src, $dest, $_[ 0 ] ); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
sub move { |
231
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
232
|
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
|
my $src = $self->_path_from_root( shift ); |
234
|
0
|
|
|
|
|
|
my $dest = $self->_path_from_root( shift ); |
235
|
|
|
|
|
|
|
# aio won't take an ending slash |
236
|
0
|
|
|
|
|
|
$dest =~ s/\/$//; |
237
|
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
aio_move( $src, $dest, $_[ 0 ] ); |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub scandir { |
242
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
aio_scandir( $self->_path_from_root( shift ), $_[ 0 ], $_[ 1 ] ); |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub rmtree { |
248
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
aio_rmtree( $self->_path_from_root( shift ), $_[ 0 ] ); |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
sub fsync { |
254
|
|
|
|
|
|
|
|
255
|
0
|
|
|
0
|
1
|
|
aio_fsync( $_[ 1 ], $_[ 2 ] ); |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
sub fdatasync { |
259
|
|
|
|
|
|
|
|
260
|
0
|
|
|
0
|
1
|
|
aio_fdatasync( $_[ 1 ], $_[ 2 ] ); |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
1; |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
__END__ |