line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Trav::Dir; |
2
|
1
|
|
|
1
|
|
765
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
4
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
5
|
1
|
|
|
1
|
|
6
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub op |
9
|
|
|
|
|
|
|
{ |
10
|
0
|
|
|
0
|
0
|
|
my ($o, $options, $name) = @_; |
11
|
0
|
0
|
|
|
|
|
if ($options->{$name}) { |
12
|
0
|
|
|
|
|
|
$o->{$name} = $options->{$name}; |
13
|
0
|
|
|
|
|
|
delete $options->{$name}; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new |
18
|
|
|
|
|
|
|
{ |
19
|
0
|
|
|
0
|
1
|
|
my ($class, %op) = @_; |
20
|
0
|
|
|
|
|
|
my $o = {}; |
21
|
0
|
|
|
|
|
|
$o->{minsize} = 0; |
22
|
0
|
|
|
|
|
|
$o->{maxsize} = 'inf'; |
23
|
0
|
|
|
|
|
|
for my $name (qw! |
24
|
|
|
|
|
|
|
verbose |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
callback |
27
|
|
|
|
|
|
|
data |
28
|
|
|
|
|
|
|
maxsize |
29
|
|
|
|
|
|
|
minsize |
30
|
|
|
|
|
|
|
no_dir |
31
|
|
|
|
|
|
|
no_trav |
32
|
|
|
|
|
|
|
only |
33
|
|
|
|
|
|
|
preprocess |
34
|
|
|
|
|
|
|
rejfile |
35
|
|
|
|
|
|
|
!) { |
36
|
0
|
|
|
|
|
|
op ($o, \%op, $name); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
# $o->{size} is a flag which tells find_files whether to check the |
39
|
|
|
|
|
|
|
# size. |
40
|
0
|
0
|
0
|
|
|
|
if ($o->{minsize} || $o->{maxsize}) { |
41
|
0
|
|
|
|
|
|
$o->{size} = 1; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
for my $k (keys %op) { |
44
|
0
|
|
|
|
|
|
carp "Unknown option $k"; |
45
|
0
|
|
|
|
|
|
delete $op{$k}; |
46
|
|
|
|
|
|
|
} |
47
|
0
|
|
|
|
|
|
bless $o, $class; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub find_files |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
0
|
1
|
|
my ($o, $dir, $f) = @_; |
53
|
0
|
0
|
0
|
|
|
|
if (! $f && ! $o->{callback}) { |
54
|
|
|
|
|
|
|
# There is no work for us to do |
55
|
0
|
|
|
|
|
|
carp "No file list and no callback"; |
56
|
0
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
my $dh; |
59
|
0
|
0
|
|
|
|
|
if (! opendir ($dh, $dir)) { |
60
|
0
|
|
|
|
|
|
warn "opendir $dir failed: $!"; |
61
|
0
|
|
|
|
|
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
0
|
|
|
|
|
|
my @files = readdir ($dh); |
64
|
0
|
|
|
|
|
|
closedir ($dh); |
65
|
0
|
0
|
|
|
|
|
if ($o->{preprocess}) { |
66
|
0
|
|
|
|
|
|
&{$o->{preprocess}} ($o->{data}, $dir, \@files); |
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
for my $file (@files) { |
69
|
0
|
0
|
0
|
|
|
|
if ($file eq '.' || $file eq '..') { |
70
|
0
|
|
|
|
|
|
next; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
0
|
0
|
|
|
|
if ($o->{rejfile} && $file =~ $o->{rejfile}) { |
73
|
0
|
0
|
|
|
|
|
if ($o->{verbose}) { |
74
|
0
|
|
|
|
|
|
print "Skipping $file\n"; |
75
|
|
|
|
|
|
|
} |
76
|
0
|
|
|
|
|
|
next; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
my $dfile = "$dir/$file"; |
79
|
0
|
0
|
|
|
|
|
if ($o->{verbose}) { |
80
|
0
|
|
|
|
|
|
print "$dir $file\n"; |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
|
my $is_dir = 0; |
83
|
0
|
0
|
|
|
|
|
if (-d $dfile) { |
84
|
0
|
0
|
0
|
|
|
|
if (! $o->{no_trav} || $dfile !~ $o->{no_trav}) { |
85
|
0
|
0
|
|
|
|
|
if (-l $dfile) { |
86
|
|
|
|
|
|
|
# Skip symbolic links |
87
|
0
|
0
|
|
|
|
|
if ($o->{verbose}) { |
88
|
0
|
|
|
|
|
|
print "Skipping symbolic link '$dfile'.\n"; |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
|
next; |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
|
find_files ($o, $dfile, $f); |
93
|
|
|
|
|
|
|
} |
94
|
0
|
0
|
|
|
|
|
if ($o->{no_dir}) { |
95
|
0
|
|
|
|
|
|
next; |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
|
$is_dir = 1; |
98
|
|
|
|
|
|
|
} |
99
|
0
|
0
|
|
|
|
|
if (-l $dfile) { |
100
|
|
|
|
|
|
|
# Skip symbolic links |
101
|
0
|
0
|
|
|
|
|
if ($o->{verbose}) { |
102
|
0
|
|
|
|
|
|
print "Skipping symbolic link '$dfile'.\n"; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
next; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
0
|
0
|
|
|
|
if (! $is_dir && $o->{size}) { |
107
|
0
|
|
|
|
|
|
my $size = -s $dfile; |
108
|
0
|
0
|
0
|
|
|
|
if ($size > $o->{maxsize} || $size < $o->{minsize}) { |
109
|
0
|
0
|
|
|
|
|
if ($o->{verbose}) { |
110
|
0
|
|
|
|
|
|
print "Skipping $file due to size $size > $o->{maxsize} or < $o->{minsize}\n"; |
111
|
|
|
|
|
|
|
} |
112
|
0
|
|
|
|
|
|
next; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
0
|
0
|
0
|
|
|
|
if (! $o->{only} || $file =~ $o->{only}) { |
116
|
0
|
|
|
|
|
|
$o->save ($dfile, $f); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub save |
122
|
|
|
|
|
|
|
{ |
123
|
0
|
|
|
0
|
0
|
|
my ($o, $dfile, $f) = @_; |
124
|
0
|
0
|
|
|
|
|
if ($f) { |
125
|
0
|
|
|
|
|
|
push @$f, $dfile; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
0
|
|
|
|
|
if ($o->{callback}) { |
128
|
0
|
|
|
|
|
|
&{$o->{callback}} ($o->{data}, $dfile); |
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |