blib/lib/File/FindUniq.pm

filter: Statementstmt 71.4% 215 / 301 Branchbran 63.9% 78 / 122 Conditioncond 62.7% 59 / 94 MC/DCmcdc 38.0% 19 / 50 Subroutinesub 70.9% 22 / 31 Podpod 100% 1 / 1 totaltotal 65.7% 394 / 599 CC 116 SCAR 56.8
CC
116
Cov
68%
uniq_files
396.2
__ANON__
12.0
__ANON__
12.0
CRAP 294.1
↑ Summary
1 package File::FindUniq;
2  
3 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Cwd qw(abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Perinci::Sub::Util qw(gen_modified_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13 2 our $DATE = '2025-05-03'; # DATE
14 2 our $DIST = 'File-FindUniq'; # DIST
15 2 our $VERSION = '0.004'; # VERSION
16  
17 10 ▶sub _glob {
Subroutine _glob: called CC=1 SCAR=0.0
18 10 require File::Find;
19  
20 10 my $dir;
21 my @res;
22 File::Find::finddepth(
23 30 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
24 30 ▶ return if -l $_;
Branch: 1 branch
BranchTrueFalseTotal
if -l $_ 0 30 30
25 30 ▶ return unless -f _;
Branch: 1 branch
BranchTrueFalseTotal
unless -f _ 10 20 30
26 2 ▶ no warnings 'once'; # $File::Find::dir
Subroutine BEGIN: called CC=1 SCAR=0.0
27 20 push @res, "$File::Find::dir/$_";
28 },
29 10 @_,
30 );
31 10 @res;
32 }
33  
34 2 our @EXPORT_OK = qw(uniq_files dupe_files);
35  
36 2 our %SPEC;
37  
38 2 $SPEC{':package'} = {
39 v => 1.1,
40 summary => 'Find unique or duplicate file {contents,names}',
41 };
42  
43 2 our %argspec_authoritative_dirs = (
44 authoritative_dirs => {
45 summary => 'Denote director(y|ies) where authoritative/"Original" copies are found',
46 'x.name.is_plural' => 1,
47 'x.name.singular' => 'authoritative_dir',
48 schema => ['array*', of=>'str*'], # XXX dirname
49 cmdline_aliases => {O=>{}},
50 },
51 );
52 2 our %argspecs_filter = (
53 include_file_patterns => {
54 summary => 'Filename (including path) regex patterns to exclude',
55 'x.name.is_plural' => 1,
56 'x.name.singular' => 'include_file_pattern',
57 schema => ['array*', of=>'str*'], # XXX re
58 cmdline_aliases => {I=>{}},
59 },
60 exclude_file_patterns => {
61 summary => 'Filename (including path) regex patterns to include',
62 'x.name.is_plural' => 1,
63 'x.name.singular' => 'exclude_file_pattern',
64 schema => ['array*', of=>'str*'], # XXX re
65 cmdline_aliases => {X=>{}},
66 },
67 exclude_empty_files => {
68 schema => 'bool*',
69 cmdline_aliases => {Z=>{}},
70 },
71 min_size => {
72 summary => 'Minimum file size to consider',
73 schema => 'filesize*',
74 },
75 max_size => {
76 summary => 'Maximum file size to consider',
77 schema => 'filesize*',
78 },
79 );
80  
81 $SPEC{uniq_files} = {
82 v => 1.1,
83 summary => 'Report duplicate or unique files, optionally perform action on them',
84 description => <<'MARKDOWN',
85  
86 Given a list of filenames, will check each file's content (and/or size, and/or
87 only name) to decide whether the file is a duplicate of another.
88  
89 There is a certain amount of flexibility on how duplicate is determined:
90 - when comparing content, various hashing algorithm is supported;
91 - when comparing size, a certain tolerance % is allowed;
92 - when comparing filename, munging can first be done.
93  
94 There is flexibility on what to do with duplicate files:
95 - just print unique/duplicate files (and let other utilities down the pipe deal
96 with them);
97 - move duplicates to some location;
98 - open the files first and prompt for action;
99 - let a Perl code process the files.
100  
101 Interface is loosely based on the `uniq` Unix command-line program.
102  
103 MARKDOWN
104 args => {
105 # actions => {
106 # 'x.name.is_plural' => 1,
107 # 'x.name.singular' => 'action',
108 # summary => 'What action(s) to perform',
109 # schema => ['array*', of=>['str*', in=>[qw/report/]], 'prefilters'=>['Array::check_uniq']],
110 # default => ['report'],
111 # description => <<'MARKDOWN',
112 #
113 #The following actions are available. More than one action can be
114 #
115 #MARKDOWN
116 # tags => ['category:input'],
117 # },
118 files => {
119 schema => ['array*' => {of=>'str*'}],
120 req => 1,
121 pos => 0,
122 slurpy => 1,
123 tags => ['category:input'],
124 },
125  
126 recurse => {
127 schema => 'bool*',
128 cmdline_aliases => {R=>{}},
129 description => <<'MARKDOWN',
130  
131 If set to true, will recurse into subdirectories.
132  
133 MARKDOWN
134 tags => ['category:input'],
135 },
136 group_by_digest => {
137 summary => 'Sort files by its digest (or size, if not computing digest), separate each different digest',
138 schema => 'bool*',
139 },
140 show_digest => {
141 summary => 'Show the digest value (or the size, if not computing digest) for each file',
142 description => <<'MARKDOWN',
143  
144 Note that this routine does not compute digest for files which have unique
145 sizes, so they will show up as empty.
146  
147 MARKDOWN
148 schema => 'true*',
149 },
150 show_size => {
151 summary => 'Show the size for each file',
152 schema => 'true*',
153 },
154 # TODO add option follow_symlinks?
155 report_unique => {
156 schema => [bool => {default=>1}],
157 summary => 'Whether to return unique items',
158 cmdline_aliases => {
159 a => {
160 summary => 'Alias for --report-unique --report-duplicate=1 (report all files)',
161 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
162 0 my $args = shift;
163 0 $args->{report_unique} = 1;
164 0 $args->{report_duplicate} = 1;
165 },
166 },
167 u => {
168 summary => 'Alias for --report-unique --report-duplicate=0',
169 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
170 0 my $args = shift;
171 0 $args->{report_unique} = 1;
172 0 $args->{report_duplicate} = 0;
173 },
174 },
175 d => {
176 summary =>
177 'Alias for --noreport-unique --report-duplicate=1',
178 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
179 0 my $args = shift;
180 0 $args->{report_unique} = 0;
181 0 $args->{report_duplicate} = 1;
182 },
183 },
184 D => {
185 summary =>
186 'Alias for --noreport-unique --report-duplicate=3',
187 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
188 0 my $args = shift;
189 0 $args->{report_unique} = 0;
190 0 $args->{report_duplicate} = 3;
191 },
192 },
193 },
194 },
195 2 report_duplicate => {
196 schema => [int => {in=>[0,1,2,3], default=>2}],
197 summary => 'Whether to return duplicate items',
198 description => <<'MARKDOWN',
199  
200 Can be set to either 0, 1, 2, or 3.
201  
202 If set to 0, duplicate items will not be returned.
203  
204 If set to 1 (the default for `dupe-files`), will return all the the duplicate
205 files. For example: `file1` contains text 'a', `file2` 'b', `file3` 'a'. Then
206 `file1` and `file3` will be returned.
207  
208 If set to 2 (the default for `uniq-files`), will only return the first of
209 duplicate items. Continuing from previous example, only `file1` will be returned
210 because `file2` is unique and `file3` contains 'a' (already represented by
211 `file1`). If one or more `--authoritative-dir` (`-O`) options are specified,
212 files under these directories will be preferred.
213  
214 If set to 3, will return all but the first of duplicate items. Continuing from
215 previous example: `file3` will be returned. This is useful if you want to keep
216 only one copy of the duplicate content. You can use the output of this routine
217 to `mv` or `rm`. Similar to the previous case, if one or more
218 `--authoritative-dir` (`-O`) options are specified, then files under these
219 directories will not be listed if possible.
220  
221 MARKDOWN
222 cmdline_aliases => {
223 },
224 },
225 algorithm => {
226 schema => ['str*'],
227 summary => "What algorithm is used to compute the digest of the content",
228 description => <<'MARKDOWN',
229  
230 The default is to use `md5`. Some algorithms supported include `crc32`, `sha1`,
231 `sha256`, as well as `Digest` to use Perl <pm:Digest> which supports a lot of
232 other algorithms, e.g. `SHA-1`, `BLAKE2b`.
233  
234 If set to '', 'none', or 'size', then digest will be set to file size. This
235 means uniqueness will be determined solely from file size. This can be quicker
236 but will generate a false positive when two files of the same size are deemed as
237 duplicate even though their content may be different.
238  
239 If set to 'name' then only name comparison will be performed. This of course can
240 potentially generate lots of false positives, but in some cases you might want
241 to compare filename for uniqueness.
242  
243 MARKDOWN
244 },
245 digest_args => {
246 schema => ['array*',
247  
248 # comment out temporarily, Perinci::Sub::GetArgs::Argv
249 # clashes with coerce rules; we should fix
250 # Perinci::Sub::GetArgs::Argv to observe coercion rules
251 # first
252 #of=>'str*',
253  
254 'x.perl.coerce_rules'=>['From_str::comma_sep']],
255 description => <<'MARKDOWN',
256  
257 Some Digest algorithms require arguments, you can pass them here.
258  
259 MARKDOWN
260 cmdline_aliases => {A=>{}},
261 },
262 show_count => {
263 schema => [bool => {default=>0}],
264 summary => "Whether to return each file content's ".
265 "number of occurence",
266 description => <<'MARKDOWN',
267  
268 1 means the file content is only encountered once (unique), 2 means there is one
269 duplicate, and so on.
270  
271 MARKDOWN
272 cmdline_aliases => {count=>{}, c=>{}},
273 },
274 detail => {
275 summary => 'Show details (a.k.a. --show-digest, --show-size, --show-count)',
276 schema => 'true*',
277 cmdline_aliases => {l=>{}},
278 },
279 %argspec_authoritative_dirs,
280 %argspecs_filter,
281 },
282 examples => [
283 {
284 summary => 'List all files which do no have duplicate contents',
285 src => 'uniq-files *',
286 src_plang => 'bash',
287 test => 0,
288 'x.doc.show_result' => 0,
289 },
290 {
291 summary => 'List all files (recursively, and in detail) which have duplicate contents (all duplicate copies), exclude some files',
292 src => q(uniq-files -R -l -d -X '\.git/' --min-size 10k .),
293 src_plang => 'bash',
294 test => 0,
295 'x.doc.show_result' => 0,
296 },
297 {
298 summary => 'Move all duplicate files (except one copy) in this directory (and subdirectories) to .dupes/',
299 src => 'uniq-files -D -R * | while read f; do mv "$f" .dupes/; done',
300 src_plang => 'bash',
301 test => 0,
302 'x.doc.show_result' => 0,
303 },
304 {
305 summary => 'List number of occurences of contents for duplicate files',
306 src => 'uniq-files -c *',
307 src_plang => 'bash',
308 test => 0,
309 'x.doc.show_result' => 0,
310 },
311 {
312 summary => 'List number of occurences of contents for all files',
313 src => 'uniq-files -a -c *',
314 src_plang => 'bash',
315 test => 0,
316 'x.doc.show_result' => 0,
317 },
318 {
319 summary => 'List all files, along with their number of content occurrences and content digest. '.
320 'Use the BLAKE2b digest algorithm. And group the files according to their digest.',
321 src => 'uniq-files -a -c --show-digest -A BLAKE2,blake2b *',
322 src_plang => 'bash',
323 test => 0,
324 'x.doc.show_result' => 0,
325 },
326 ],
327 };
328 11 ▶sub uniq_files {
Subroutine uniq_files: called CC=108 SCAR=59.8
Pod documented
329 11 my %args = @_;
330  
331 11 my $files = delete $args{files};
332 11 ▶ return [400, "Please specify files"] if !$files || !@$files;
Branch: 1 branch
BranchTrueFalseTotal
unless $files and @$files 0 11 11
Condition33%1/3
$files and @$files
!ll&&!rl&&r
0011
MC/DC0%0/2
$files and @$files
$files @$files
Truth table33%1/3
A and B
A= $filesB= @$files
ABresult
0X0
100
111
333 11 my $recurse = delete($args{recurse});
334 11 ▶ my $report_unique = delete($args{report_unique}) // 1;
Condition100%2/2
delete $args{"report_unique"} // 1
l!l
65
MC/DC100%1/1
delete $args{"report_unique"} // 1
delete $args{"report_unique"}
Truth table100%2/2
A
A= delete $args{"report_unique"}
Aresult
11
00
335 11 ▶ my $report_duplicate = delete($args{report_duplicate}) // 2;
Condition100%2/2
delete $args{"report_duplicate"} // 2
l!l
92
MC/DC100%1/1
delete $args{"report_duplicate"} // 2
delete $args{"report_duplicate"}
Truth table100%2/2
A
A= delete $args{"report_duplicate"}
Aresult
11
00
336 11 ▶ my $show_count = delete($args{show_count}) // 0;
Condition100%2/2
delete $args{"show_count"} // 0
l!l
110
MC/DC100%1/1
delete $args{"show_count"} // 0
delete $args{"show_count"}
Truth table100%2/2
A
A= delete $args{"show_count"}
Aresult
11
00
337 11 ▶ my $show_digest = delete($args{show_digest}) // 0;
Condition100%2/2
delete $args{"show_digest"} // 0
l!l
29
MC/DC100%1/1
delete $args{"show_digest"} // 0
delete $args{"show_digest"}
Truth table100%2/2
A
A= delete $args{"show_digest"}
Aresult
11
00
338 11 ▶ my $show_size = delete($args{show_size}) // 0;
Condition100%2/2
delete $args{"show_size"} // 0
l!l
110
MC/DC100%1/1
delete $args{"show_size"} // 0
delete $args{"show_size"}
Truth table100%2/2
A
A= delete $args{"show_size"}
Aresult
11
00
339 11 my $digest_args = delete($args{digest_args});
340 11 ▶ my $algorithm = delete($args{algorithm}) // ($digest_args ? 'Digest' : 'md5');
Branch: 1 branch
BranchTrueFalseTotal
$digest_args ? : 0 9 9
Condition100%2/2
delete $args{"algorithm"} // ($digest_args ? "Digest" : "md5")
l!l
29
MC/DC100%1/1
delete $args{"algorithm"} // ($digest_args ? "Digest" : "md5")
delete $args{"algorithm"}
Truth table100%2/2
A
A= delete $args{"algorithm"}
Aresult
11
00
341 11 my $group_by_digest = delete($args{group_by_digest});
342 11 my $detail = delete($args{detail});
343 11 my $authoritative_dirs = delete($args{authoritative_dirs});
344 11 my $include_file_patterns = delete($args{include_file_patterns});
345 11 my $exclude_file_patterns = delete($args{exclude_file_patterns});
346 11 ▶ my $exclude_empty_files = delete($args{exclude_empty_files}) // 0;
Condition50%1/2
delete $args{"exclude_empty_files"} // 0
l!l
011
MC/DC0%0/1
delete $args{"exclude_empty_files"} // 0
delete $args{"exclude_empty_files"}
Truth table50%1/2
A
A= delete $args{"exclude_empty_files"}
Aresult
11
00
347 11 my $min_size = delete($args{min_size});
348 11 my $max_size = delete($args{max_size});
349 return [400, "Unknown argument(s): ".join(", ", sort keys %args)]
350 0 ▶ if grep {!/\A-/} keys %args;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not /\A-/;} keys %args 0 11 11
351  
352 11 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) 0 11 11
353 0 $show_digest = 1;
354 0 $show_size = 1;
355 0 $show_count = 1;
356 }
357  
358 11 ▶ my @authoritative_dirs = $authoritative_dirs && @$authoritative_dirs ?
Branch: 1 branch
BranchTrueFalseTotal
$authoritative_dirs && @$authoritative_dirs ? : 2 9 11
Condition66%2/3
$authoritative_dirs and @$authoritative_dirs
!ll&&!rl&&r
902
MC/DC50%1/2
$authoritative_dirs and @$authoritative_dirs
$authoritative_dirs @$authoritative_dirs
Truth table66%2/3
A and B
A= $authoritative_dirsB= @$authoritative_dirs
ABresult
0X0
100
111
359 @$authoritative_dirs : ();
360 11 for my $dir (@authoritative_dirs) {
361 2 ▶ (-d $dir) or return [400, "Authoritative dir '$dir' does not exist or not a directory"];
Branch: 1 branch
BranchTrueFalseTotal
-d $dir or return [400, "Authoritative dir '${dir}' does not exist or not a directory"] 2 0 2
362 2 ▶ my $abs_dir = abs_path $dir or return [400, "Cannot get absolute path for authoritative dir '$dir'"];
Branch: 1 branch
BranchTrueFalseTotal
my $abs_dir = abs_path($dir) or return [400, "Cannot get absolute path for authoritative dir '${dir}'"] 2 0 2
363 2 $dir = $abs_dir;
364 }
365 #log_trace "authoritative_dirs=%s", \@authoritative_dirs if @authoritative_dirs;
366  
367 11 my @include_re;
368 11 ▶ for my $re0 (@{ $include_file_patterns // [] }) {
Condition50%1/2
$include_file_patterns // []
l!l
011
MC/DC0%0/1
$include_file_patterns // []
$include_file_patterns
Truth table50%1/2
A
A= $include_file_patterns
Aresult
11
00
369 0 require Regexp::Util;
370 0 my $re;
371 0 ▶ if (ref $re0 eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $re0 eq 'Regexp') { } 0 0 0
372 0 $re = $re0;
373 } else {
374 0 eval { $re = Regexp::Util::deserialize_regexp("qr($re0)") };
375 0 ▶ return [400, "Invalid/unsafe regex pattern in include_file_patterns '$re0': $@"] if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
376 0 ▶ return [400, "Unsafe regex pattern (contains embedded code) in include_file_patterns '$re0'"] if Regexp::Util::regexp_seen_evals($re);
Branch: 1 branch
BranchTrueFalseTotal
if Regexp::Util::regexp_seen_evals($re) 0 0 0
377 }
378 0 push @include_re, $re;
379 }
380 11 my @exclude_re;
381 11 ▶ for my $re0 (@{ $exclude_file_patterns // [] }) {
Condition50%1/2
$exclude_file_patterns // []
l!l
011
MC/DC0%0/1
$exclude_file_patterns // []
$exclude_file_patterns
Truth table50%1/2
A
A= $exclude_file_patterns
Aresult
11
00
382 0 require Regexp::Util;
383 0 my $re;
384 0 ▶ if (ref $re0 eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $re0 eq 'Regexp') { } 0 0 0
385 0 $re = $re0;
386 } else {
387 0 eval { $re = Regexp::Util::deserialize_regexp("qr($re0)") };
388 0 ▶ return [400, "Invalid/unsafe regex pattern in exclude_file_patterns '$re0': $@"] if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
389 0 ▶ return [400, "Unsafe regex pattern (contains embedded code) in exclude_file_patterns '$re0'"] if Regexp::Util::regexp_seen_evals($re);
Branch: 1 branch
BranchTrueFalseTotal
if Regexp::Util::regexp_seen_evals($re) 0 0 0
390 }
391 0 push @exclude_re, $re;
392 }
393  
394 11 ▶ if ($recurse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recurse) 5 6 11
395 $files = [ map {
396 5 ▶ if (-l $_) {
Branch: 2 branches
BranchTrueFalseTotal
if (-l $_) { } 0 35 35
elsif (-d _) { } 10 25 35
397 0 ();
398 } elsif (-d _) {
399 10 (_glob($_));
400 } else {
401 25 ($_);
402 }
403 } @$files ];
404 }
405  
406 FILTER: {
407 11 my $ffiles;
408 FILE:
409 11 for my $f (@$files) {
410 87 ▶ if (-l $f) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $f) 0 87 87
411 0 log_warn "File '$f' is a symlink, ignored";
412 0 next FILE;
413 }
414 87 ▶ if (-d _) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d _) 12 75 87
415 12 log_warn "File '$f' is a directory, ignored";
416 12 next FILE;
417 }
418 75 ▶ unless (-f _) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f _) 0 75 75
419 0 log_warn "File '$f' is not a regular file, ignored";
420 0 next FILE;
421 }
422  
423 75 ▶ if (@include_re) {
Branch: 1 branch
BranchTrueFalseTotal
if (@include_re) 0 75 75
424 0 my $included;
425 0 for my $re (@include_re) {
426 0 ▶ if ($f =~ $re) { $included++; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /$re/) 0 0 0
427 }
428 0 ▶ unless ($included) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($included) 0 0 0
429 0 log_info "File '$f' is not in --include-file-patterns, skipped";
430 0 next FILE;
431 }
432 }
433 75 ▶ if (@exclude_re) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exclude_re) 0 75 75
434 0 for my $re (@exclude_re) {
435 0 ▶ if ($f =~ $re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /$re/) 0 0 0
436 0 log_info "File '$f' is in --exclude-file-patterns, skipped";
437 0 next FILE;
438 }
439 }
440 }
441  
442 75 my $size = -s $f;
443 75 ▶ if ($exclude_empty_files && !$size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exclude_empty_files and not $size) 0 75 75
Condition33%1/3
$exclude_empty_files and not $size
!ll&&!rl&&r
7500
MC/DC0%0/2
$exclude_empty_files and not $size
$exclude_empty_files not $size
Truth table33%1/3
A and not(B)
A= $exclude_empty_filesB= not $size
ABresult
0X0
100
111
444 0 log_info "File '$f' is empty, skipped by option -Z";
445 0 next FILE;
446 }
447 75 ▶ if (defined($min_size) && $size < $min_size) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min_size and $size < $min_size) 0 75 75
Condition33%1/3
defined $min_size and $size < $min_size
!ll&&!rl&&r
7500
MC/DC0%0/2
defined $min_size and $size < $min_size
defined $min_size $size < $min_size
Truth table33%1/3
A and B
A= defined $min_sizeB= $size < $min_size
ABresult
0X0
100
111
448 0 log_info "File '$f' (size=$size) is smaller than min_file ($min_size), skipped";
449 0 next FILE;
450 }
451 75 ▶ if (defined($max_size) && $size > $max_size) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max_size and $size > $max_size) 0 75 75
Condition33%1/3
defined $max_size and $size > $max_size
!ll&&!rl&&r
7500
MC/DC0%0/2
defined $max_size and $size > $max_size
defined $max_size $size > $max_size
Truth table33%1/3
A and B
A= defined $max_sizeB= $size > $max_size
ABresult
0X0
100
111
452 0 log_info "File '$f' (size=$size) is larger than max_file ($max_size), skipped";
453 0 next FILE;
454 }
455  
456 75 push @$ffiles, $f;
457 }
458 11 $files = $ffiles;
459 } # FILTER
460  
461 11 my %basename_paths; # key = basename (computed), value = [path, ...]
462 my %path_basenames; # key = path, value = basename
463 GROUP_FILE_NAMES: {
464 11 for my $f (@$files) {
465 #my $path = abs_path($f);
466 75 (my $basename = $f) =~ s!.+/!!;
467 75 ▶ $basename_paths{$basename} //= [];
Condition50%1/2
$basename_paths{$basename} //= []
l!l
075
MC/DC0%0/1
$basename_paths{$basename} //= []
$basename_paths{$basename}
Truth table50%1/2
A
A= $basename_paths{$basename}
Aresult
11
00
468 75 push @{ $basename_paths{$basename} }, $f
469 0 ▶ unless grep { $_ eq $f } @{ $basename_paths{$basename} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $f;} @{$basename_paths{$basename};} 75 0 75
470 75 $path_basenames{$f} = $basename;
471 }
472 }
473 #use DD; print "basename_paths: "; dd \%basename_paths;
474  
475 11 my %size_counts; # key = size, value = number of files having that size
476 my %size_paths; # key = size, value = [path, ...]
477 11 my %path_sizes; # key = path, value = file size, for caching stat()
478 GET_FILE_SIZES: {
479 11 for my $f (@$files) {
480 75 my @st = stat $f;
481 75 ▶ unless (@st) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@st) 0 75 75
482 0 log_error("Can't stat file `$f`: $!, skipped");
483 0 next;
484 }
485 75 $size_counts{$st[7]}++;
486 75 ▶ $size_paths{$st[7]} //= [];
Condition100%2/2
$size_paths{$st[7]} //= []
l!l
5322
MC/DC100%1/1
$size_paths{$st[7]} //= []
$size_paths{$st[7]}
Truth table100%2/2
A
A= $size_paths{$st[7]}
Aresult
11
00
487 75 push @{$size_paths{$st[7]}}, $f;
488 75 $path_sizes{$f} = $st[7];
489 }
490 }
491 #use DD; print "size_paths: "; dd \%size_paths;
492  
493 # calculate digest for all files having non-unique sizes
494 11 my %digest_counts; # key = digest, value = num of files having that digest
495 my %digest_paths; # key = digest, value = [file, ...]
496 11 my %path_digests; # key = path, value = file digest
497 CALC_FILE_DIGESTS: {
498 11 require File::Digest;
499  
500 11 for my $f (@$files) {
501 75 ▶ next unless defined $path_sizes{$f}; # just checking. all files should have sizes.
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path_sizes{$f} 0 75 75
502  
503 75 my $digest;
504 75 ▶ if ($algorithm eq '' || $algorithm eq 'none' || $algorithm eq 'size') {
Branch: 2 branches
BranchTrueFalseTotal
if ($algorithm eq '' or $algorithm eq 'none' or $algorithm eq 'size') { } 9 66 75
elsif ($algorithm eq 'name') { } 0 66 66
Condition66%4/6
$algorithm eq "" or $algorithm eq "none" or $algorithm eq "size"
l!l&&r!l&&!r
9066
$algorithm eq "" or $algorithm eq "none"
l!l&&r!l&&!r
0966
MC/DC33%1/3
$algorithm eq "" or $algorithm eq "none" or $algorithm eq "size"
$algorithm eq "" $algorithm eq "none" $algorithm eq "size"
Truth table50%2/4
A or B or C
A= $algorithm eq ""B= $algorithm eq "none"C= $algorithm eq "size"
ABCresult
1XX1
01X1
0011
0000
505 9 $digest = $path_sizes{$f};
506 } elsif ($algorithm eq 'name') {
507 0 $digest = $path_basenames{$f};
508 } else {
509 66 ▶ next if $size_counts{ $path_sizes{$f} } == 1; # skip unique file sizes.
Branch: 1 branch
BranchTrueFalseTotal
if $size_counts{$path_sizes{$f}} == 1 6 60 66
510 60 my $res = File::Digest::digest_file(
511 file=>$f, algorithm=>$algorithm, digest_args=>$digest_args);
512 60 ▶ return [500, "Can't calculate digest for file '$f': $res->[0] - $res->[1]"]
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 60 60
513 unless $res->[0] == 200;
514 60 $digest = $res->[2];
515 }
516 69 $digest_counts{$digest}++;
517 69 ▶ $digest_paths{$digest} //= [];
Condition100%2/2
$digest_paths{$digest} //= []
l!l
3534
MC/DC100%1/1
$digest_paths{$digest} //= []
$digest_paths{$digest}
Truth table100%2/2
A
A= $digest_paths{$digest}
Aresult
11
00
518 69 push @{$digest_paths{$digest}}, $f;
519 69 $path_digests{$f} = $digest;
520 }
521 }
522 #use DD; print "digest_paths: "; dd \%digest_paths;
523 #use DD; print "path_digests: "; dd \%path_digests;
524  
525 11 my %path_counts; # key = path, value = num of files having file content
526 11 for my $f (@$files) {
527 75 ▶ next unless defined $path_sizes{$f}; # just checking, all files should have sizes
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path_sizes{$f} 0 75 75
528 75 ▶ if (!defined($path_digests{$f})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $path_digests{$f}) { } 6 69 75
529 6 $path_counts{$f} = $size_counts{ $path_sizes{$f} };
530 } else {
531 69 $path_counts{$f} = $digest_counts{ $path_digests{$f} };
532 }
533 }
534 #use DD; print "path_counts: "; dd \%path_counts;
535  
536 SORT_DUPLICATE_FILES: {
537 11 ▶ last unless @authoritative_dirs;
Branch: 1 branch
BranchTrueFalseTotal
unless @authoritative_dirs 9 2 11
538 2 my $hash = \%digest_paths;
539 2 for my $key (keys %$hash) {
540 10 my @files = @{ $hash->{$key} };
541 10 my @abs_files;
542 10 ▶ next unless @files > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @files > 1 6 4 10
543 4 for my $file (@files) {
544 12 ▶ my $abs_file = abs_path $file or do {
Branch: 1 branch
BranchTrueFalseTotal
my $abs_file = abs_path($file) or do { log_error("Cannot find absolute path for duplicate file '${file}', skipping duplicate set %s", \@files) } 12 0 12
545 0 log_error "Cannot find absolute path for duplicate file '$file', skipping duplicate set %s", \@files;
546 };
547 12 push @abs_files, $abs_file;
548 }
549  
550 #log_trace "Duplicate files before sorting: %s", \@files;
551 12 @files = map { $files[$_] } sort {
552 4 my $file_a = $abs_files[$a];
553 10 my $file_a_in_authoritative_dirs = 0;
554 10 my $subdir_len_file_a;
555 10 for my $d (@authoritative_dirs) {
556 0 ▶ if ($file_a =~ m!\A\Q$d\E(?:/|\z)(.*)!) { $file_a_in_authoritative_dirs++; $subdir_len_file_a = length($1); last }
Branch: 1 branch
BranchTrueFalseTotal
if ($file_a =~ m[\A\Q$d\E(?:/|\z)(.*)]) 0 10 10
557 }
558 10 my $file_b = $abs_files[$b];
559 10 my $file_b_in_authoritative_dirs = 0;
560 10 my $subdir_len_file_b;
561 10 for my $d (@authoritative_dirs) {
562 10 ▶ if ($file_b =~ m!\A\Q$d\E(?:/|\z)(.*)!) { $file_b_in_authoritative_dirs++; $subdir_len_file_b = length($1); last }
Branch: 1 branch
BranchTrueFalseTotal
if ($file_b =~ m[\A\Q$d\E(?:/|\z)(.*)]) 2 8 10
563 }
564 #log_trace " file_a=<$file_a>, in authoritative_dirs? $file_a_in_authoritative_dirs";
565 #log_trace " file_b=<$file_b>, in authoritative_dirs? $file_b_in_authoritative_dirs";
566 # files located near the root of authoritative dir is preferred
567 # to deeper files. this is done by comparing subdir_len
568 10 ▶ ($file_a_in_authoritative_dirs ? $subdir_len_file_a : 9999) <=> ($file_b_in_authoritative_dirs ? $subdir_len_file_b : 9999) ||
Branch: 2 branches
BranchTrueFalseTotal
$file_a_in_authoritative_dirs ? : 0 10 10
$file_b_in_authoritative_dirs ? : 2 8 10
Condition66%2/3
($file_a_in_authoritative_dirs ? $subdir_len_file_a : 9999) <=> ($file_b_in_authoritative_dirs ? $subdir_len_file_b : 9999) || $file_a cmp $file_b
l!l&&r!l&&!r
280
MC/DC0%0/2
($file_a_in_authoritative_dirs ? $subdir_len_file_a : 9999) <=> ($file_b_in_authoritative_dirs ? $subdir_len_file_b : 9999) || $file_a cmp $file_b
($file_a_in_authoritative_dirs ? $subdir_len_file_a : 9999) <=> ($file_b_in_authoritative_dirs ? $subdir_len_file_b : 9999) $file_a cmp $file_b
Truth table66%2/3
A || B
A= ($file_a_in_authoritative_dirs ? $subdir_len_file_a : 9999) <=> ($file_b_in_authoritative_dirs ? $subdir_len_file_b : 9999)B= $file_a cmp $file_b
ABresult
1X1
011
000
569 $file_a cmp $file_b;
570 } 0..$#files;
571 #log_trace "Duplicate files after sorting: %s", \@files;
572  
573 4 $hash->{$key} = \@files;
574 }
575 }
576  
577 #$log->trace("report_duplicate=$report_duplicate");
578 11 my @files;
579 11 for my $f (sort keys %path_counts) {
580 75 ▶ if ($path_counts{$f} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path_counts{$f} == 1) { } 24 51 75
581 24 log_trace "unique file '$f'";
582 24 ▶ push @files, $f if $report_unique;
Branch: 1 branch
BranchTrueFalseTotal
if $report_unique 14 10 24
583 } else {
584 51 log_trace "duplicate file '$f'";
585 51 my $is_first_copy = $f eq $digest_paths{ $path_digests{$f} }[0];
586 51 log_trace "is first copy? <$is_first_copy>";
587 51 ▶ if ($report_duplicate == 0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($report_duplicate == 0) { } 6 45 51
elsif ($report_duplicate == 1) { } 15 30 45
elsif ($report_duplicate == 2) { } 21 9 30
elsif ($report_duplicate == 3) { } 9 0 9
588 # do not report dupe files
589 } elsif ($report_duplicate == 1) {
590 15 push @files, $f;
591 } elsif ($report_duplicate == 2) {
592 21 ▶ push @files, $f if $is_first_copy;
Branch: 1 branch
BranchTrueFalseTotal
if $is_first_copy 6 15 21
593 } elsif ($report_duplicate == 3) {
594 9 ▶ push @files, $f unless $is_first_copy;
Branch: 1 branch
BranchTrueFalseTotal
unless $is_first_copy 6 3 9
595 } else {
596 0 die "Invalid value for --report-duplicate ".
597 "'$report_duplicate', please choose 0/1/2/3";
598 }
599 }
600 }
601  
602 GROUP_FILES_BY_DIGEST: {
603 11 ▶ last unless $group_by_digest;
Branch: 1 branch
BranchTrueFalseTotal
unless $group_by_digest 10 1 11
604 @files = sort {
605 1 $path_sizes{$a} <=> $path_sizes{$b} ||
606 20 ▶ ($path_digests{$a} // '') cmp ($path_digests{$b} // '')
Condition71%5/7
$path_sizes{$a} <=> $path_sizes{$b} || ($path_digests{$a} // '') cmp ($path_digests{$b} // '')
l!l&&r!l&&!r
776
$path_digests{$a} // ""
l!l
130
$path_digests{$b} // ""
l!l
130
MC/DC0%0/2
$path_sizes{$a} <=> $path_sizes{$b} || ($path_digests{$a} // '') cmp ($path_digests{$b} // '')
$path_sizes{$a} <=> $path_sizes{$b} $path_digests{$a}
MC/DC0%0/1
$path_digests{$b} // ""
$path_digests{$b}
Truth table66%2/3
A || B
A= $path_sizes{$a} <=> $path_sizes{$b}B= $path_digests{$a}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $path_digests{$b}
Aresult
11
00
607 } @files;
608 }
609  
610 11 my @rows;
611 my %resmeta;
612 11 my $last_digest;
613 11 for my $f (@files) {
614 41 ▶ my $digest = $path_digests{$f} // $path_sizes{$f};
Condition66%2/3
$path_digests{$f} // $path_sizes{$f}
l!l&&r!l&&!r
3740
MC/DC0%0/2
$path_digests{$f} // $path_sizes{$f}
$path_digests{$f} $path_sizes{$f}
Truth table66%2/3
A // B
A= $path_digests{$f}B= $path_sizes{$f}
ABresult
1X1
011
000
615  
616 # add separator row
617 41 ▶ if ($group_by_digest && defined $last_digest && $digest ne $last_digest) {
Branch: 1 branch
BranchTrueFalseTotal
if ($group_by_digest and defined $last_digest and $digest ne $last_digest) 4 37 41
Condition100%6/6
$group_by_digest and defined $last_digest and $digest ne $last_digest
!ll&&!rl&&r
3344
$group_by_digest and defined $last_digest
!ll&&!rl&&r
3218
MC/DC100%3/3
$group_by_digest and defined $last_digest and $digest ne $last_digest
$group_by_digest defined $last_digest $digest ne $last_digest
Truth table100%4/4
A and B and C
A= $group_by_digestB= defined $last_digestC= $digest ne $last_digest
ABCresult
0XX0
10X0
1100
1111
618 4 ▶ push @rows, ($show_count || $show_digest || $show_size) ? {} : '';
Branch: 1 branch
BranchTrueFalseTotal
$show_count || $show_digest || $show_size ? : 4 0 4
Condition33%2/6
$show_count or $show_digest or $show_size
l!l&&r!l&&!r
400
$show_count or $show_digest
l!l&&r!l&&!r
040
MC/DC0%0/3
$show_count or $show_digest or $show_size
$show_count $show_digest $show_size
Truth table25%1/4
A or B or C
A= $show_countB= $show_digestC= $show_size
ABCresult
1XX1
01X1
0011
0000
619 }
620  
621 41 my $row;
622 41 ▶ if ($show_count || $show_digest || $show_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($show_count or $show_digest or $show_size) { } 19 22 41
Condition100%6/6
$show_count or $show_digest or $show_size
l!l&&r!l&&!r
17222
$show_count or $show_digest
l!l&&r!l&&!r
51224
MC/DC100%3/3
$show_count or $show_digest or $show_size
$show_count $show_digest $show_size
Truth table100%4/4
A or B or C
A= $show_countB= $show_digestC= $show_size
ABCresult
1XX1
01X1
0011
0000
623 19 $row = {file=>$f};
624 19 ▶ $row->{count} = $path_counts{$f} if $show_count;
Branch: 1 branch
BranchTrueFalseTotal
if $show_count 5 14 19
625 19 ▶ $row->{digest} = $path_digests{$f} if $show_digest;
Branch: 1 branch
BranchTrueFalseTotal
if $show_digest 12 7 19
626 19 ▶ $row->{size} = $path_sizes{$f} if $show_size;
Branch: 1 branch
BranchTrueFalseTotal
if $show_size 2 17 19
627 } else {
628 22 $row = $f;
629 }
630 41 push @rows, $row;
631 41 $last_digest = $digest;
632 }
633  
634 11 ▶ $resmeta{'table.fields'} = [qw/file size digest count/]
Branch: 1 branch
BranchTrueFalseTotal
if $show_count or $show_digest or $show_size 4 7 11
Condition100%6/6
$show_count or $show_digest or $show_size
l!l&&r!l&&!r
317
$show_count or $show_digest
l!l&&r!l&&!r
128
MC/DC100%3/3
$show_count or $show_digest or $show_size
$show_count $show_digest $show_size
Truth table100%4/4
A or B or C
A= $show_countB= $show_digestC= $show_size
ABCresult
1XX1
01X1
0011
0000
635 if $show_count || $show_digest || $show_size;
636  
637 11 [200, "OK", \@rows, \%resmeta];
638 }
639  
640 # dupe_files
641 gen_modified_sub(
642 base_name => 'uniq_files',
643 output_name => 'dupe_files',
644 description => <<'MARKDOWN',
645  
646 This is a thin wrapper for <prog:uniq-files>. It defaults `report_unique` to 0
647 and `report_duplicate` to 1.
648  
649 MARKDOWN
650 modify_args => {
651 2 ▶ report_unique => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
652 2 $_[0]{schema} = [bool => {default=>0}];
653 },
654 2 ▶ report_duplicate => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
655 2 $_[0]{schema} = [int => {in=>[0,1,2,3], default=>1}];
656 },
657 },
658 2 ▶ modify_meta => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
659 $_[0]{examples} = [
660 {
661 2 summary => 'List all files (recursively, and in detail)NN which have duplicate contents (all duplicate copies)',
662 src => 'dupe-files -lR *',
663 src_plang => 'bash',
664 test => 0,
665 'x.doc.show_result' => 0,
666 },
667 ];
668 },
669 0 ▶ output_code => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
670 0 my %args = @_;
671 0 ▶ $args{report_unique} //= 0;
Condition0%0/2
$args{"report_unique"} //= 0
l!l
00
MC/DC0%0/1
$args{"report_unique"} //= 0
$args{"report_unique"}
Truth table0%0/2
A
A= $args{"report_unique"}
Aresult
11
00
672 0 ▶ $args{report_duplicate} //= 1;
Condition0%0/2
$args{"report_duplicate"} //= 1
l!l
00
MC/DC0%0/1
$args{"report_duplicate"} //= 1
$args{"report_duplicate"}
Truth table0%0/2
A
A= $args{"report_duplicate"}
Aresult
11
00
673 0 uniq_files(%args);
674 },
675 2 );
676  
677 # uniq_filenames
678 gen_modified_sub(
679 base_name => 'uniq_files',
680 output_name => 'uniq_filenames',
681 description => <<'MARKDOWN',
682  
683 This is a thin wrapper for <prog:uniq-files>. It sets `algorithm` to `name`.
684  
685 MARKDOWN
686 remove_args => ['algorithm'],
687 2 ▶ modify_meta => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
688 $_[0]{examples} = [
689 {
690 2 summary => 'Find unique filenames in two directories',
691 src => 'uniq-filenames -uR dir1 dir2',
692 src_plang => 'bash',
693 test => 0,
694 'x.doc.show_result' => 0,
695 },
696 ];
697 },
698 0 ▶ output_code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
699 0 my %args = @_;
700 0 uniq_files(%args, algorithm => 'name');
701 },
702 2 );
703  
704 # dupe_filenames
705 gen_modified_sub(
706 base_name => 'uniq_files',
707 output_name => 'dupe_filenames',
708 description => <<'MARKDOWN',
709  
710 This is a thin wrapper for <prog:uniq-files>. It sets `algorithm` to `name`,
711 defaults `report_unique` to 0 and `report_duplicate` to 1.
712  
713 MARKDOWN
714 remove_args => ['algorithm'],
715 modify_args => {
716 2 ▶ report_unique => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
717 2 $_[0]{schema} = [bool => {default=>0}];
718 },
719 2 ▶ report_duplicate => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
720 2 $_[0]{schema} = [int => {in=>[0,1,2,3], default=>1}];
721 },
722 },
723 2 ▶ modify_meta => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
724 $_[0]{examples} = [
725 {
726 2 summary => 'Find duplicate filenames in two directories',
727 src => 'dupe-filenames -R dir1 dir2',
728 src_plang => 'bash',
729 test => 0,
730 'x.doc.show_result' => 0,
731 },
732 ];
733 },
734 0 ▶ output_code => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
735 0 my %args = @_;
736 0 ▶ $args{report_unique} //= 0;
Condition0%0/2
$args{"report_unique"} //= 0
l!l
00
MC/DC0%0/1
$args{"report_unique"} //= 0
$args{"report_unique"}
Truth table0%0/2
A
A= $args{"report_unique"}
Aresult
11
00
737 0 ▶ $args{report_duplicate} //= 1;
Condition0%0/2
$args{"report_duplicate"} //= 1
l!l
00
MC/DC0%0/1
$args{"report_duplicate"} //= 1
$args{"report_duplicate"}
Truth table0%0/2
A
A= $args{"report_duplicate"}
Aresult
11
00
738 0 uniq_files(%args, algorithm=>'name');
739 },
740 2 );
741  
742 # uniq_filenames_between_two_dirs
743 gen_modified_sub(
744 base_name => 'uniq_files',
745 output_name => 'uniq_filenames_between_two_dirs',
746 description => <<'MARKDOWN',
747  
748 This is a thin wrapper for <prog:uniq-files>. It sets `algorithm` to `name`,
749 `recurse` to true. It also accepts two directory names instead of one+ dir/file
750 names.
751  
752 MARKDOWN
753 add_args => {
754 dir1 => {
755 schema => 'dirname*',
756 req => 1,
757 pos => 0,
758 },
759 dir2 => {
760 schema => 'dirname*',
761 req => 1,
762 pos => 1,
763 },
764 },
765 remove_args => ['algorithm', 'files', 'recurse'],
766 2 ▶ modify_meta => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
767 $_[0]{examples} = [
768 {
769 2 summary => 'Find unique filenames in two directories',
770 src => 'uniq-filenames-between-two-dirs -u dir1 dir2',
771 src_plang => 'bash',
772 test => 0,
773 'x.doc.show_result' => 0,
774 },
775 ];
776 },
777 0 ▶ output_code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
778 0 my %args = @_;
779 0 my $dir1 = delete $args{dir1};
780 0 my $dir2 = delete $args{dir2};
781 0 uniq_files(
782 %args,
783 files => [$dir1, $dir2],
784 algorithm => 'name',
785 recurse => 1,
786 );
787 },
788 2 );
789  
790 # dupe_filenames_between_two_dirs
791 gen_modified_sub(
792 base_name => 'uniq_files',
793 output_name => 'dupe_filenames_between_two_dirs',
794 description => <<'MARKDOWN',
795  
796 This is a thin wrapper for <prog:uniq-files>. It sets `algorithm` to `name`,
797 `recurse` to true, defaults `report_unique` to 0 and `report_duplicate` to 1. It
798 also accepts two directory names instead of one+ dir/file names.
799  
800 MARKDOWN
801 add_args => {
802 dir1 => {
803 schema => 'dirname*',
804 req => 1,
805 pos => 0,
806 },
807 dir2 => {
808 schema => 'dirname*',
809 req => 1,
810 pos => 1,
811 },
812 },
813 remove_args => ['algorithm', 'files', 'recurse'],
814 modify_args => {
815 2 ▶ report_unique => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
816 2 $_[0]{schema} = [bool => {default=>0}];
817 },
818 2 ▶ report_duplicate => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
819 2 $_[0]{schema} = [int => {in=>[0,1,2,3], default=>1}];
820 },
821 },
822 2 ▶ modify_meta => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
823 $_[0]{examples} = [
824 {
825 2 summary => 'Find duplicate filenames in two directories',
826 src => 'dupe-filenames-between-two-dirs dir1 dir2',
827 src_plang => 'bash',
828 test => 0,
829 'x.doc.show_result' => 0,
830 },
831 ];
832 },
833 0 ▶ output_code => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
834 0 my %args = @_;
835 0 my $dir1 = delete $args{dir1};
836 0 my $dir2 = delete $args{dir2};
837 0 ▶ $args{report_unique} //= 0;
Condition0%0/2
$args{"report_unique"} //= 0
l!l
00
MC/DC0%0/1
$args{"report_unique"} //= 0
$args{"report_unique"}
Truth table0%0/2
A
A= $args{"report_unique"}
Aresult
11
00
838 0 ▶ $args{report_duplicate} //= 1;
Condition0%0/2
$args{"report_duplicate"} //= 1
l!l
00
MC/DC0%0/1
$args{"report_duplicate"} //= 1
$args{"report_duplicate"}
Truth table0%0/2
A
A= $args{"report_duplicate"}
Aresult
11
00
839 0 uniq_files(
840 %args,
841 files => [$dir1, $dir2],
842 algorithm => 'name',
843 recurse => 1,
844 );
845 },
846 2 );
847  
848  
849 2 1;
850 # ABSTRACT: Find unique or duplicate file {contents,names}
851  
852 __END__
↑ Summary