line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Dir::Dumper::Scanner; |
2
|
|
|
|
|
|
|
$File::Dir::Dumper::Scanner::VERSION = '0.6.5'; |
3
|
1
|
|
|
1
|
|
141340
|
use warnings; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
5
|
1
|
|
|
1
|
|
5
|
use autodie; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5234
|
use 5.012; |
|
1
|
|
|
|
|
6
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
6
|
use parent 'File::Dir::Dumper::Base'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
42
|
use Carp (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
510
|
use File::Find::Object (); |
|
1
|
|
|
|
|
11530
|
|
|
1
|
|
|
|
|
28
|
|
14
|
1
|
|
|
1
|
|
6
|
use Devel::CheckOS qw( os_is ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
5
|
use POSIX qw(strftime); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
17
|
1
|
|
|
1
|
|
70
|
use List::Util qw(min); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
112
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
10
|
use Class::XSAccessor accessors => { |
20
|
|
|
|
|
|
|
_digest_cache => '_digest_cache', |
21
|
|
|
|
|
|
|
_digests => '_digests', |
22
|
|
|
|
|
|
|
_file_find => '_file_find', |
23
|
|
|
|
|
|
|
_group_cache => '_group_cache', |
24
|
|
|
|
|
|
|
_last_result => '_last_result', |
25
|
|
|
|
|
|
|
_queue => '_queue', |
26
|
|
|
|
|
|
|
_reached_end => '_reached_end', |
27
|
|
|
|
|
|
|
_result => '_result', |
28
|
|
|
|
|
|
|
_user_cache => '_user_cache', |
29
|
1
|
|
|
1
|
|
6
|
}; |
|
1
|
|
|
|
|
3
|
|
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
982
|
use Digest (); |
|
1
|
|
|
|
|
545
|
|
|
1
|
|
|
|
|
938
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _init |
35
|
|
|
|
|
|
|
{ |
36
|
3
|
|
|
3
|
|
7
|
my $self = shift; |
37
|
3
|
|
|
|
|
6
|
my $args = shift; |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
7
|
my $dir_to_dump = $args->{dir}; |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
33
|
$self->_file_find( |
42
|
|
|
|
|
|
|
File::Find::Object->new( |
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
followlink => 0, |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
$dir_to_dump, |
47
|
|
|
|
|
|
|
) |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
698
|
$self->_queue( [] ); |
51
|
|
|
|
|
|
|
|
52
|
3
|
|
|
|
|
23
|
$self->_add( |
53
|
|
|
|
|
|
|
{ |
54
|
|
|
|
|
|
|
type => "header", |
55
|
|
|
|
|
|
|
dir_to_dump => $dir_to_dump, |
56
|
|
|
|
|
|
|
stream_type => "Directory Dump" |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
3
|
|
|
|
|
11
|
$self->_digests( undef() ); |
61
|
3
|
100
|
|
|
|
11
|
if ( exists( $args->{digests} ) ) |
62
|
|
|
|
|
|
|
{ |
63
|
2
|
|
|
|
|
4
|
my $digests = {}; |
64
|
2
|
|
|
|
|
4
|
foreach my $d ( @{ $args->{digests} } ) |
|
2
|
|
|
|
|
24
|
|
65
|
|
|
|
|
|
|
{ |
66
|
4
|
50
|
|
|
|
12
|
if ( exists $digests->{$d} ) |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
|
|
0
|
Carp::confess("Duplicate digest '$d'!"); |
69
|
|
|
|
|
|
|
} |
70
|
4
|
|
|
|
|
22
|
$digests->{$d} = 1; |
71
|
|
|
|
|
|
|
} |
72
|
2
|
50
|
|
|
|
6
|
if ( !%$digests ) |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
|
|
0
|
Carp::confess("The list of digests is empty."); |
75
|
|
|
|
|
|
|
} |
76
|
2
|
|
|
|
|
13
|
$self->_digests( [ sort { $a cmp $b } keys %$digests ] ); |
|
2
|
|
|
|
|
13
|
|
77
|
|
|
|
|
|
|
} |
78
|
3
|
|
100
|
|
|
19
|
my $base = ( $args->{digest_cache} || 'Dummy' ); |
79
|
3
|
50
|
|
|
|
18
|
if ( $base !~ /\A[A-Za-z_][A-Za-z_0-9]*\z/ ) |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
|
|
0
|
Carp::confess("Invalid digest_cache format."); |
82
|
|
|
|
|
|
|
} |
83
|
3
|
|
|
|
|
9
|
my $cl = "File::Dir::Dumper::DigestCache::$base"; |
84
|
|
|
|
|
|
|
## no critic |
85
|
3
|
|
|
|
|
223
|
eval "require $cl"; |
86
|
|
|
|
|
|
|
## use critic |
87
|
3
|
50
|
|
|
|
21
|
if ($@) |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
|
|
0
|
die $@; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
$self->_digest_cache( |
92
|
|
|
|
|
|
|
scalar $cl->new( |
93
|
|
|
|
|
|
|
{ |
94
|
3
|
|
100
|
|
|
41
|
params => ( $args->{digest_cache_params} || +{} ), |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
) |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
13
|
$self->_user_cache( {} ); |
101
|
3
|
|
|
|
|
9
|
$self->_group_cache( {} ); |
102
|
|
|
|
|
|
|
|
103
|
3
|
|
|
|
|
8
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub _add |
107
|
|
|
|
|
|
|
{ |
108
|
19
|
|
|
19
|
|
38
|
my $self = shift; |
109
|
19
|
|
|
|
|
27
|
my $token = shift; |
110
|
|
|
|
|
|
|
|
111
|
19
|
|
|
|
|
30
|
push @{ $self->_queue() }, $token; |
|
19
|
|
|
|
|
53
|
|
112
|
|
|
|
|
|
|
|
113
|
19
|
|
|
|
|
36
|
return; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub fetch |
117
|
|
|
|
|
|
|
{ |
118
|
21
|
|
|
21
|
1
|
960028
|
my $self = shift; |
119
|
|
|
|
|
|
|
|
120
|
21
|
100
|
|
|
|
37
|
if ( !@{ $self->_queue() } ) |
|
21
|
|
|
|
|
90
|
|
121
|
|
|
|
|
|
|
{ |
122
|
14
|
|
|
|
|
42
|
$self->_populate_queue(); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
21
|
|
|
|
|
34
|
return shift( @{ $self->_queue() } ); |
|
21
|
|
|
|
|
83
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _up_to_level |
129
|
|
|
|
|
|
|
{ |
130
|
9
|
|
|
9
|
|
18
|
my $self = shift; |
131
|
9
|
|
|
|
|
50
|
my $target_level = shift; |
132
|
|
|
|
|
|
|
|
133
|
9
|
|
|
|
|
22
|
my $last_result = $self->_last_result(); |
134
|
|
|
|
|
|
|
|
135
|
9
|
|
|
|
|
18
|
for my $level ( |
136
|
9
|
|
|
|
|
30
|
reverse( $target_level .. $#{ $last_result->dir_components() } ) ) |
137
|
|
|
|
|
|
|
{ |
138
|
4
|
|
|
|
|
15
|
$self->_add( |
139
|
|
|
|
|
|
|
{ |
140
|
|
|
|
|
|
|
type => "updir", |
141
|
|
|
|
|
|
|
depth => $level + 1, |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
9
|
|
|
|
|
19
|
return; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub _find_new_common_depth |
150
|
|
|
|
|
|
|
{ |
151
|
8
|
|
|
8
|
|
18
|
my $self = shift; |
152
|
|
|
|
|
|
|
|
153
|
8
|
|
|
|
|
17
|
my $result = $self->_result(); |
154
|
8
|
|
|
|
|
21
|
my $last_result = $self->_last_result(); |
155
|
|
|
|
|
|
|
|
156
|
8
|
|
|
|
|
15
|
my $depth = 0; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $upper_limit = min( |
159
|
8
|
|
|
|
|
21
|
scalar( @{ $last_result->dir_components() } ), |
160
|
8
|
|
|
|
|
14
|
scalar( @{ $result->dir_components() } ), |
|
8
|
|
|
|
|
36
|
|
161
|
|
|
|
|
|
|
); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
FIND_I: |
164
|
8
|
|
|
|
|
29
|
while ( $depth < $upper_limit ) |
165
|
|
|
|
|
|
|
{ |
166
|
2
|
100
|
|
|
|
13
|
if ( $last_result->dir_components()->[$depth] ne |
167
|
|
|
|
|
|
|
$result->dir_components()->[$depth] ) |
168
|
|
|
|
|
|
|
{ |
169
|
1
|
|
|
|
|
3
|
last FIND_I; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
continue |
173
|
|
|
|
|
|
|
{ |
174
|
1
|
|
|
|
|
2
|
$depth++; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
8
|
|
|
|
|
31
|
return $depth; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
BEGIN |
181
|
|
|
|
|
|
|
{ |
182
|
1
|
50
|
|
1
|
|
9
|
if ( os_is('Unix') ) |
183
|
|
|
|
|
|
|
{ |
184
|
|
|
|
|
|
|
*_my_getpwuid = sub { |
185
|
5
|
|
|
5
|
|
4963
|
my $uid = shift; |
186
|
5
|
|
|
|
|
1046
|
return scalar( getpwuid($uid) ); |
187
|
1
|
|
|
|
|
986044
|
}; |
188
|
|
|
|
|
|
|
*_my_getgrgid = sub { |
189
|
3
|
|
|
3
|
|
6
|
my $gid = shift; |
190
|
3
|
|
|
|
|
264
|
return scalar( getgrgid($gid) ); |
191
|
1
|
|
|
|
|
819
|
}; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
else |
194
|
|
|
|
|
|
|
{ |
195
|
0
|
|
|
|
|
0
|
*_my_getpwuid = sub { return "unknown"; }; |
|
0
|
|
|
|
|
0
|
|
196
|
0
|
|
|
|
|
0
|
*_my_getgrgid = sub { return "unknown"; }; |
|
0
|
|
|
|
|
0
|
|
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
sub _get_user_name |
201
|
|
|
|
|
|
|
{ |
202
|
8
|
|
|
8
|
|
506
|
my $self = shift; |
203
|
8
|
|
|
|
|
17
|
my $uid = shift; |
204
|
|
|
|
|
|
|
|
205
|
8
|
100
|
|
|
|
40
|
if ( !exists( $self->_user_cache()->{$uid} ) ) |
206
|
|
|
|
|
|
|
{ |
207
|
3
|
|
|
|
|
10
|
$self->_user_cache()->{$uid} = _my_getpwuid($uid); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
8
|
|
|
|
|
44
|
return $self->_user_cache()->{$uid}; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub _get_group_name |
214
|
|
|
|
|
|
|
{ |
215
|
8
|
|
|
8
|
|
12
|
my $self = shift; |
216
|
8
|
|
|
|
|
14
|
my $gid = shift; |
217
|
|
|
|
|
|
|
|
218
|
8
|
100
|
|
|
|
34
|
if ( !exists( $self->_group_cache()->{$gid} ) ) |
219
|
|
|
|
|
|
|
{ |
220
|
3
|
|
|
|
|
11
|
$self->_group_cache()->{$gid} = _my_getgrgid($gid); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
8
|
|
|
|
|
73
|
return $self->_group_cache()->{$gid}; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub _calc_file_digests_key |
227
|
|
|
|
|
|
|
{ |
228
|
5
|
|
|
5
|
|
14
|
my ( $self, $stat ) = @_; |
229
|
|
|
|
|
|
|
|
230
|
5
|
|
|
|
|
13
|
my $digests = $self->_digests; |
231
|
|
|
|
|
|
|
|
232
|
5
|
100
|
|
|
|
15
|
if ( !defined $digests ) |
233
|
|
|
|
|
|
|
{ |
234
|
1
|
|
|
|
|
15
|
return []; |
235
|
|
|
|
|
|
|
} |
236
|
4
|
|
|
|
|
9
|
my $result = $self->_result(); |
237
|
4
|
|
|
|
|
10
|
my $path = $result->path; |
238
|
|
|
|
|
|
|
my $ret = $self->_digest_cache->get_digests( |
239
|
|
|
|
|
|
|
{ |
240
|
|
|
|
|
|
|
path => $result->full_components, |
241
|
|
|
|
|
|
|
mtime => $stat->[9], |
242
|
|
|
|
|
|
|
digests => $digests, |
243
|
|
|
|
|
|
|
calc_cb => sub { |
244
|
4
|
|
|
4
|
|
52
|
my %ret; |
245
|
4
|
|
|
|
|
10
|
foreach my $d (@$digests) |
246
|
|
|
|
|
|
|
{ |
247
|
8
|
|
|
|
|
1179
|
my $o = Digest->new($d); |
248
|
8
|
|
|
|
|
304
|
open my $fh, '<', $path; |
249
|
8
|
|
|
|
|
2753
|
binmode $fh; |
250
|
8
|
|
|
|
|
1357
|
$o->addfile($fh); |
251
|
8
|
|
|
|
|
221
|
$ret{$d} = $o->hexdigest; |
252
|
8
|
|
|
|
|
30
|
close($fh); |
253
|
|
|
|
|
|
|
} |
254
|
4
|
|
|
|
|
293
|
return \%ret; |
255
|
|
|
|
|
|
|
}, |
256
|
|
|
|
|
|
|
} |
257
|
4
|
|
|
|
|
16
|
); |
258
|
4
|
|
|
|
|
69
|
return [ digests => $ret, ]; |
259
|
|
|
|
|
|
|
} |
260
|
|
|
|
|
|
|
my $PERM_MASK = oct('07777'); |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub _calc_file_or_dir_token |
263
|
|
|
|
|
|
|
{ |
264
|
8
|
|
|
8
|
|
18
|
my $self = shift; |
265
|
|
|
|
|
|
|
|
266
|
8
|
|
|
|
|
18
|
my $result = $self->_result(); |
267
|
|
|
|
|
|
|
|
268
|
8
|
|
|
|
|
139
|
my @stat = stat( $result->path() ); |
269
|
|
|
|
|
|
|
|
270
|
8
|
50
|
|
|
|
34
|
if ( not @stat ) |
271
|
|
|
|
|
|
|
{ |
272
|
0
|
|
|
|
|
0
|
Carp::confess( |
273
|
0
|
|
|
|
|
0
|
"Could not successfully stat <<@{[$result->path()]}>> - $!"); |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
return { |
277
|
|
|
|
|
|
|
filename => $result->full_components()->[-1], |
278
|
8
|
|
|
|
|
90
|
depth => scalar( @{ $result->full_components() } ), |
279
|
|
|
|
|
|
|
perms => sprintf( "%04o", ( $stat[2] & $PERM_MASK ) ), |
280
|
|
|
|
|
|
|
mtime => strftime( "%Y-%m-%dT%H:%M:%S", localtime( $stat[9] ) ), |
281
|
|
|
|
|
|
|
user => $self->_get_user_name( $stat[4] ), |
282
|
|
|
|
|
|
|
group => $self->_get_group_name( $stat[5] ), |
283
|
|
|
|
|
|
|
( |
284
|
|
|
|
|
|
|
$result->is_dir() |
285
|
|
|
|
|
|
|
? ( type => "dir", ) |
286
|
|
|
|
|
|
|
: ( |
287
|
|
|
|
|
|
|
type => "file", |
288
|
|
|
|
|
|
|
size => $stat[7], |
289
|
8
|
100
|
|
|
|
41
|
@{ $self->_calc_file_digests_key( \@stat ) }, |
|
5
|
|
|
|
|
19
|
|
290
|
|
|
|
|
|
|
) |
291
|
|
|
|
|
|
|
), |
292
|
|
|
|
|
|
|
}; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
sub _populate_queue |
296
|
|
|
|
|
|
|
{ |
297
|
14
|
|
|
14
|
|
23
|
my $self = shift; |
298
|
|
|
|
|
|
|
|
299
|
14
|
100
|
|
|
|
49
|
if ( $self->_reached_end() ) |
300
|
|
|
|
|
|
|
{ |
301
|
2
|
|
|
|
|
10
|
return; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
12
|
|
|
|
|
46
|
$self->_result( $self->_file_find->next_obj() ); |
305
|
|
|
|
|
|
|
|
306
|
12
|
100
|
|
|
|
4140
|
if ( !$self->_last_result() ) |
|
|
100
|
|
|
|
|
|
307
|
|
|
|
|
|
|
{ |
308
|
3
|
|
|
|
|
13
|
$self->_add( { type => "dir", depth => 0 } ); |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
elsif ( !$self->_result() ) |
311
|
|
|
|
|
|
|
{ |
312
|
1
|
|
|
|
|
6
|
$self->_up_to_level(-1); |
313
|
|
|
|
|
|
|
|
314
|
1
|
|
|
|
|
5
|
$self->_add( { type => "footer" } ); |
315
|
|
|
|
|
|
|
|
316
|
1
|
|
|
|
|
3
|
$self->_reached_end(1); |
317
|
|
|
|
|
|
|
} |
318
|
|
|
|
|
|
|
else |
319
|
|
|
|
|
|
|
{ |
320
|
8
|
|
|
|
|
28
|
$self->_up_to_level( $self->_find_new_common_depth() ); |
321
|
|
|
|
|
|
|
|
322
|
8
|
|
|
|
|
27
|
$self->_add( $self->_calc_file_or_dir_token() ); |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
12
|
|
|
|
|
69
|
$self->_last_result( $self->_result() ); |
326
|
|
|
|
|
|
|
} |
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
1; # End of File::Dir::Dumper |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
__END__ |