/usr/local/lib/perl5/5.44.0/File/Find.pm

filter: Statementstmt 0.0% 0 / 393 Branchbran 0.0% 0 / 316 Conditioncond 0.0% 0 / 90 MC/DCmcdc 0.0% 0 / 54 Subroutinesub 0.0% 0 / 12 Podpod 28.5% 2 / 7 totaltotal 0.2% 2 / 872 CC 194 SCAR 78.7
CC
194
Cov
0%
_find_dir
4692.0
_find_dir_symlnk
2862.0
_find_opt
1560.0
CRAP 2623.5
↑ Summary /usr/local/lib/perl5/5.44.0/IO/Socket/IP.pm »
1 package File::Find;
2  
3 use 5.006;
4 use strict;
5 use warnings;
6 use warnings::register;
7  
8 use Exporter 'import';
9 require Cwd;
10 require File::Basename;
11 require File::Spec;
12  
13 our $VERSION = '1.44';
14 our @EXPORT = qw(find finddepth);
15  
16 my $Is_VMS = $^O eq 'VMS';
17 my $Is_Win32 = $^O eq 'MSWin32';
18  
19  
20 # Should ideally be my() not our() but local() currently
21 # refuses to operate on lexicals
22  
23 our %SLnkSeen;
24 our ($wanted_callback, $avoid_nlink, $bydepth, $no_chdir, $follow,
25 $follow_skip, $full_check, $untaint, $untaint_skip, $untaint_pat,
26 $pre_process, $post_process, $dangling_symlinks);
27  
28 sub contract_name {
29 0 ▶ my ($cdir,$fn) = @_;
Subroutine contract_name: not called CC=4 SCAR=30.0
Pod undocumented
30  
31 0 ▶ return substr($cdir,0,rindex($cdir,'/')) if $fn eq $File::Find::current_dir;
Branch: 1 branch
BranchTrueFalseTotal
if $fn eq $File::Find::current_dir 0 0 0
32  
33 0 $cdir = substr($cdir,0,rindex($cdir,'/')+1);
34  
35 0 $fn =~ s|^\./||;
36  
37 0 my $abs_name= $cdir . $fn;
38  
39 0 ▶ if (substr($fn,0,3) eq '../') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($fn, 0, 3) eq "../") 0 0 0
40 0 ▶ 1 while $abs_name =~ s!/[^/]*/\.\./+!/!;
Branch: 1 branch
BranchTrueFalseTotal
$abs_name =~ s[/[^/]*/\.\./+][/] and do { '???' } 0 0 0
41 }
42  
43 0 return $abs_name;
44 }
45  
46 sub _is_absolute {
47 0 ▶ return $_[0] =~ m|^(?:[A-Za-z]:)?/| if $Is_Win32;
Subroutine _is_absolute: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $Is_Win32 0 0 0
48 0 return substr($_[0], 0, 1) eq '/';
49 }
50  
51 sub _is_root {
52 0 ▶ return $_[0] =~ m|^(?:[A-Za-z]:)?/\z| if $Is_Win32;
Subroutine _is_root: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if $Is_Win32 0 0 0
53 0 return $_[0] eq '/';
54 }
55  
56 sub PathCombine($$) {
57 0 ▶ my ($Base,$Name) = @_;
Subroutine PathCombine: not called CC=6 SCAR=37.4
Pod undocumented
58 0 my $AbsName;
59  
60 0 ▶ if (_is_absolute($Name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_absolute($Name)) { } 0 0 0
61 0 $AbsName= $Name;
62 }
63 else {
64 0 $AbsName= contract_name($Base,$Name);
65 }
66  
67 # (simple) check for recursion
68 0 my $newlen= length($AbsName);
69 0 ▶ if ($newlen <= length($Base)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newlen <= length $Base) 0 0 0
70 0 ▶ if (($newlen == length($Base) || substr($Base,$newlen,1) eq '/')
Branch: 1 branch
BranchTrueFalseTotal
if ($newlen == length $Base || substr($Base, $newlen, 1) eq "/" and $AbsName eq substr($Base, 0, $newlen)) 0 0 0
Condition0%0/6
$newlen == length $Base || substr($Base, $newlen, 1) eq "/" and $AbsName eq substr($Base, 0, $newlen)
!ll&&!rl&&r
000
$newlen == length $Base or substr($Base, $newlen, 1) eq "/"
l!l&&r!l&&!r
000
MC/DC0%0/3
$newlen == length $Base || substr($Base, $newlen, 1) eq "/" and $AbsName eq substr($Base, 0, $newlen)
$newlen == length $Base substr($Base, $newlen, 1) eq "/" $AbsName eq substr($Base, 0, $newlen)
Truth table0%0/5
A or B and C
A= $newlen == length $BaseB= substr($Base, $newlen, 1) eq "/"C= $AbsName eq substr($Base, 0, $newlen)
ABCresult
00X0
1X00
0100
1X11
0111
71 && $AbsName eq substr($Base,0,$newlen))
72 {
73 0 return undef;
74 }
75 }
76 0 return $AbsName;
77 }
78  
79 sub Follow_SymLink($) {
80 0 ▶ my ($AbsName) = @_;
Subroutine Follow_SymLink: not called CC=14 SCAR=53.5
Pod undocumented
81  
82 0 my ($NewName,$DEV, $INO);
83 0 ($DEV, $INO)= lstat $AbsName;
84  
85 0 ▶ while (-l _) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l _) 0 0 0
86 0 ▶ if ($SLnkSeen{$DEV, $INO}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::SLnkSeen{join $;, $DEV, $INO}++) 0 0 0
87 0 ▶ if ($follow_skip < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::follow_skip < 2) { } 0 0 0
88 0 die "$AbsName is encountered a second time";
89 }
90 else {
91 0 return undef;
92 }
93 }
94 0 my $Link = readlink($AbsName);
95 # canonicalize directory separators
96 0 ▶ $Link =~ s|\\|/|g if $Is_Win32;
Branch: 1 branch
BranchTrueFalseTotal
if $Is_Win32 0 0 0
97 0 $NewName= PathCombine($AbsName, $Link);
98 0 ▶ unless(defined $NewName) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $NewName) { } 0 0 0
99 0 ▶ if ($follow_skip < 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::follow_skip < 2) { } 0 0 0
100 0 die "$AbsName is a recursive symbolic link";
101 }
102 else {
103 0 return undef;
104 }
105 }
106 else {
107 0 $AbsName= $NewName;
108 }
109 0 ($DEV, $INO) = lstat($AbsName);
110 0 ▶ return undef unless defined $DEV; # dangling symbolic link
Branch: 1 branch
BranchTrueFalseTotal
unless defined $DEV 0 0 0
111 }
112  
113 0 ▶ if ($full_check && defined $DEV && $SLnkSeen{$DEV, $INO}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::full_check and defined $DEV and $File::Find::SLnkSeen{join $;, $DEV, $INO}++) 0 0 0
Condition0%0/6
$File::Find::full_check and defined $DEV and $File::Find::SLnkSeen{join $;, $DEV, $INO}++
!ll&&!rl&&r
000
$File::Find::full_check and defined $DEV
!ll&&!rl&&r
000
MC/DC0%0/3
$File::Find::full_check and defined $DEV and $File::Find::SLnkSeen{join $;, $DEV, $INO}++
$File::Find::full_check defined $DEV $File::Find::SLnkSeen{join $;, $DEV, $INO}++
Truth table0%0/4
A and B and C
A= $File::Find::full_checkB= defined $DEVC= $File::Find::SLnkSeen{join $;, $DEV, $INO}++
ABCresult
0XX0
10X0
1100
1111
114 0 ▶ if ( ($follow_skip < 1) || ((-d _) && ($follow_skip < 2)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::follow_skip < 1 or -d _ and $File::Find::follow_skip < 2) { } 0 0 0
Condition0%0/6
$File::Find::follow_skip < 1 or -d _ and $File::Find::follow_skip < 2
l!l&&r!l&&!r
000
-d _ and $File::Find::follow_skip < 2
!ll&&!rl&&r
000
MC/DC0%0/3
$File::Find::follow_skip < 1 or -d _ and $File::Find::follow_skip < 2
$File::Find::follow_skip < 1 -d _ $File::Find::follow_skip < 2
Truth table0%0/4
A or B and C
A= $File::Find::follow_skip < 1B= -d _C= $File::Find::follow_skip < 2
ABCresult
1XX1
0111
00X0
0100
115 0 die "$AbsName encountered a second time";
116 }
117 else {
118 0 return undef;
119 }
120 }
121  
122 0 return $AbsName;
123 }
124  
125 our($dir, $name, $fullname, $prune);
126 sub _find_dir_symlnk($$$);
127 sub _find_dir($$$);
128  
129 # check whether or not a scalar variable is tainted
130 # (code straight from the Camel, 3rd ed., page 561)
131 sub is_tainted_pp {
132 0 ▶ my $arg = shift;
Subroutine is_tainted_pp: not called CC=1 SCAR=6.9
Pod undocumented
133 0 my $nada = substr($arg, 0, 0); # zero-length
134 0 local $@;
135 0 eval { eval "# $nada" };
136 0 return length($@) != 0;
137 }
138  
139  
140 sub _find_opt {
141 0 ▶ my $wanted = shift;
Subroutine _find_opt: not called CC=39 SCAR=73.5
142 0 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
143 0 ▶ die "invalid top directory" unless defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
144  
145 # This function must local()ize everything because callbacks may
146 # call find() or finddepth()
147  
148 0 local %SLnkSeen;
149 0 local ($wanted_callback, $avoid_nlink, $bydepth, $no_chdir, $follow,
150 $follow_skip, $full_check, $untaint, $untaint_skip, $untaint_pat,
151 $pre_process, $post_process, $dangling_symlinks);
152 0 local($dir, $name, $fullname, $prune);
153 0 local *_ = \my $a;
154  
155 0 ▶ my $cwd = $wanted->{bydepth} ? Cwd::fastcwd() : Cwd::getcwd();
Branch: 1 branch
BranchTrueFalseTotal
$wanted->{'bydepth'} ? : 0 0 0
156 0 ▶ if ($Is_VMS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS) 0 0 0
157 # VMS returns this by default in VMS format which just doesn't
158 # work for the rest of this module.
159 0 $cwd = VMS::Filespec::unixpath($cwd);
160  
161 # Apparently this is not expected to have a trailing space.
162 # To attempt to make VMS/UNIX conversions mostly reversible,
163 # a trailing slash is needed. The run-time functions ignore the
164 # resulting double slash, but it causes the perl tests to fail.
165 0 $cwd =~ s#/\z##;
166  
167 # This comes up in upper case now, but should be lower.
168 # In the future this could be exact case, no need to change.
169 }
170 0 my $cwd_untainted = $cwd;
171 0 my $check_t_cwd = 1;
172 0 $wanted_callback = $wanted->{wanted};
173 0 $bydepth = $wanted->{bydepth};
174 0 $pre_process = $wanted->{preprocess};
175 0 $post_process = $wanted->{postprocess};
176 0 $no_chdir = $wanted->{no_chdir};
177 0 $full_check = $wanted->{follow};
178 0 ▶ $follow = $full_check || $wanted->{follow_fast};
Condition0%0/3
$File::Find::full_check || $wanted->{'follow_fast'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$File::Find::full_check || $wanted->{'follow_fast'}
$File::Find::full_check $wanted->{'follow_fast'}
Truth table0%0/3
A || B
A= $File::Find::full_checkB= $wanted->{'follow_fast'}
ABresult
1X1
011
000
179 0 $follow_skip = $wanted->{follow_skip};
180 0 $untaint = $wanted->{untaint};
181 0 $untaint_pat = $wanted->{untaint_pattern};
182 0 $untaint_skip = $wanted->{untaint_skip};
183 0 $dangling_symlinks = $wanted->{dangling_symlinks};
184  
185 # for compatibility reasons (find.pl, find2perl)
186 0 local our ($topdir, $topdev, $topino, $topmode, $topnlink);
187  
188 # a symbolic link to a directory doesn't increase the link count
189 0 ▶ $avoid_nlink = $follow || $File::Find::dont_use_nlink;
Condition0%0/3
$File::Find::follow || $File::Find::dont_use_nlink
l!l&&r!l&&!r
000
MC/DC0%0/2
$File::Find::follow || $File::Find::dont_use_nlink
$File::Find::follow $File::Find::dont_use_nlink
Truth table0%0/3
A || B
A= $File::Find::followB= $File::Find::dont_use_nlink
ABresult
1X1
011
000
190  
191 0 my ($abs_dir, $Is_Dir);
192  
193 Proc_Top_Item:
194 0 foreach my $TOP (@_) {
195 0 my $top_item = $TOP;
196 0 ▶ $top_item = VMS::Filespec::unixify($top_item) if $Is_VMS;
Branch: 1 branch
BranchTrueFalseTotal
if $Is_VMS 0 0 0
197  
198 0 ▶ ($topdev,$topino,$topmode,$topnlink) = $follow ? stat $top_item : lstat $top_item;
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::follow ? : 0 0 0
199  
200 # canonicalize directory separators
201 0 ▶ $top_item =~ s|[/\\]|/|g if $Is_Win32;
Branch: 1 branch
BranchTrueFalseTotal
if $Is_Win32 0 0 0
202  
203 # no trailing / unless path is root
204 0 ▶ $top_item =~ s|/\z|| unless _is_root($top_item);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_root($top_item) 0 0 0
205  
206 0 $Is_Dir= 0;
207  
208 0 ▶ if ($follow) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::follow) { } 0 0 0
209  
210 0 ▶ if (_is_absolute($top_item)) {
Branch: 2 branches
BranchTrueFalseTotal
if (_is_absolute($top_item)) { } 0 0 0
elsif ($top_item eq $File::Find::current_dir) { } 0 0 0
211 0 $abs_dir = $top_item;
212 }
213 elsif ($top_item eq $File::Find::current_dir) {
214 0 $abs_dir = $cwd;
215 }
216 else { # care about any ../
217 0 ▶ $top_item =~ s/\.dir\z//i if $Is_VMS;
Branch: 1 branch
BranchTrueFalseTotal
if $Is_VMS 0 0 0
218 0 $abs_dir = contract_name("$cwd/",$top_item);
219 }
220 0 $abs_dir= Follow_SymLink($abs_dir);
221 0 ▶ unless (defined $abs_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $abs_dir) 0 0 0
222 0 ▶ if ($dangling_symlinks) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::dangling_symlinks) 0 0 0
223 0 ▶ if (ref $dangling_symlinks eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $File::Find::dangling_symlinks eq 'CODE') { } 0 0 0
224 0 $dangling_symlinks->($top_item, $cwd);
225 } else {
226 0 warnings::warnif "$top_item is a dangling symbolic link\n";
227 }
228 }
229 0 next Proc_Top_Item;
230 }
231  
232 0 ▶ if (-d _) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d _) 0 0 0
233 0 ▶ $top_item =~ s/\.dir\z//i if $Is_VMS;
Branch: 1 branch
BranchTrueFalseTotal
if $Is_VMS 0 0 0
234 0 _find_dir_symlnk($wanted, $abs_dir, $top_item);
235 0 $Is_Dir= 1;
236 }
237 }
238 else { # no follow
239 0 $topdir = $top_item;
240 0 ▶ unless (defined $topnlink) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $File::Find::topnlink) 0 0 0
241 0 warnings::warnif "Can't stat $top_item: $!\n";
242 0 next Proc_Top_Item;
243 }
244 0 ▶ if (-d _) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d _) { } 0 0 0
245 0 ▶ $top_item =~ s/\.dir\z//i if $Is_VMS;
Branch: 1 branch
BranchTrueFalseTotal
if $Is_VMS 0 0 0
246 0 _find_dir($wanted, $top_item, $topnlink);
247 0 $Is_Dir= 1;
248 }
249 else {
250 0 $abs_dir= $top_item;
251 }
252 }
253  
254 0 ▶ unless ($Is_Dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Is_Dir) 0 0 0
255 0 ▶ unless (($_,$dir) = File::Basename::fileparse($abs_dir)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($_, $File::Find::dir) = File::Basename::fileparse($abs_dir)) 0 0 0
256 0 ($dir,$_) = ('./', $top_item);
257 }
258  
259 0 $abs_dir = $dir;
260 0 ▶ if (( $untaint ) && (is_tainted($dir) )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::untaint and &is_tainted($File::Find::dir)) 0 0 0
Condition0%0/3
$File::Find::untaint and &is_tainted($File::Find::dir)
!ll&&!rl&&r
000
MC/DC0%0/2
$File::Find::untaint and &is_tainted($File::Find::dir)
$File::Find::untaint &is_tainted($File::Find::dir)
Truth table0%0/3
A and B
A= $File::Find::untaintB= &is_tainted($File::Find::dir)
ABresult
0X0
100
111
261 0 ( $abs_dir ) = $dir =~ m|$untaint_pat|;
262 0 ▶ unless (defined $abs_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $abs_dir) 0 0 0
263 0 ▶ if ($untaint_skip == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::untaint_skip == 0) { } 0 0 0
264 0 die "directory $dir is still tainted";
265 }
266 else {
267 0 next Proc_Top_Item;
268 }
269 }
270 }
271  
272 0 ▶ unless ($no_chdir || chdir $abs_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($File::Find::no_chdir or chdir $abs_dir) 0 0 0
Condition0%0/3
$File::Find::no_chdir or chdir $abs_dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$File::Find::no_chdir or chdir $abs_dir
$File::Find::no_chdir chdir $abs_dir
Truth table0%0/3
A or B
A= $File::Find::no_chdirB= chdir $abs_dir
ABresult
1X1
011
000
273 0 warnings::warnif "Couldn't chdir $abs_dir: $!\n";
274 0 next Proc_Top_Item;
275 }
276  
277 0 $name = $abs_dir . $_; # $File::Find::name
278 0 ▶ $_ = $name if $no_chdir;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::no_chdir 0 0 0
279  
280 0 { $wanted_callback->() }; # protect against wild "next"
281  
282 }
283  
284 0 ▶ unless ( $no_chdir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($File::Find::no_chdir) 0 0 0
285 0 ▶ if ( ($check_t_cwd) && (($untaint) && (is_tainted($cwd) )) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check_t_cwd and ($File::Find::untaint and &is_tainted($cwd))) 0 0 0
Condition0%0/6
$check_t_cwd and ($File::Find::untaint and &is_tainted($cwd))
!ll&&!rl&&r
000
$File::Find::untaint and &is_tainted($cwd)
!ll&&!rl&&r
000
MC/DC0%0/3
$check_t_cwd and ($File::Find::untaint and &is_tainted($cwd))
$check_t_cwd $File::Find::untaint &is_tainted($cwd)
Truth table0%0/4
A and B and C
A= $check_t_cwdB= $File::Find::untaintC= &is_tainted($cwd)
ABCresult
0XX0
10X0
1100
1111
286 0 ( $cwd_untainted ) = $cwd =~ m|$untaint_pat|;
287 0 ▶ unless (defined $cwd_untainted) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cwd_untainted) 0 0 0
288 0 die "insecure cwd in find(depth)";
289 }
290 0 $check_t_cwd = 0;
291 }
292 0 ▶ unless (chdir $cwd_untainted) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $cwd_untainted) 0 0 0
293 0 die "Can't cd to $cwd: $!\n";
294 }
295 }
296 }
297 }
298  
299 # API:
300 # $wanted
301 # $p_dir : "parent directory"
302 # $nlink : what came back from the stat
303 # preconditions:
304 # chdir (if not no_chdir) to dir
305  
306 sub _find_dir($$$) {
307 0 ▶ my ($wanted, $p_dir, $nlink) = @_;
Subroutine _find_dir: not called CC=68 SCAR=84.5
308 0 my ($CdLvl,$Level) = (0,0);
309 0 my @Stack;
310 my @filenames;
311 0 my ($subcount,$sub_nlink);
312 0 my $SE= [];
313 0 my $dir_name= $p_dir;
314 0 my $dir_pref;
315 0 my $dir_rel = $File::Find::current_dir;
316 0 my $tainted = 0;
317 0 my $no_nlink;
318  
319 0 ▶ if ($Is_VMS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS) { } 0 0 0
320 # VMS is returning trailing .dir on directories
321 # and trailing . on files and symbolic links
322 # in UNIX syntax.
323 #
324  
325 0 ▶ $p_dir =~ s/\.(dir)?$//i unless $p_dir eq '.';
Branch: 1 branch
BranchTrueFalseTotal
unless $p_dir eq "." 0 0 0
326  
327 0 ▶ $dir_pref = ($p_dir =~ m/[\]>]+$/ ? $p_dir : "$p_dir/" );
Branch: 1 branch
BranchTrueFalseTotal
$p_dir =~ /[\]>]+$/ ? : 0 0 0
328 }
329 else {
330 0 ▶ $dir_pref = _is_root($p_dir) ? $p_dir : "$p_dir/";
Branch: 1 branch
BranchTrueFalseTotal
_is_root($p_dir) ? : 0 0 0
331 }
332  
333 0 local ($dir, $name, $prune);
334  
335 0 ▶ unless ( $no_chdir || ($p_dir eq $File::Find::current_dir)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($File::Find::no_chdir or $p_dir eq $File::Find::current_dir) 0 0 0
Condition0%0/3
$File::Find::no_chdir or $p_dir eq $File::Find::current_dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$File::Find::no_chdir or $p_dir eq $File::Find::current_dir
$File::Find::no_chdir $p_dir eq $File::Find::current_dir
Truth table0%0/3
A or B
A= $File::Find::no_chdirB= $p_dir eq $File::Find::current_dir
ABresult
1X1
011
000
336 0 my $udir = $p_dir;
337 0 ▶ if (( $untaint ) && (is_tainted($p_dir) )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::untaint and &is_tainted($p_dir)) 0 0 0
Condition0%0/3
$File::Find::untaint and &is_tainted($p_dir)
!ll&&!rl&&r
000
MC/DC0%0/2
$File::Find::untaint and &is_tainted($p_dir)
$File::Find::untaint &is_tainted($p_dir)
Truth table0%0/3
A and B
A= $File::Find::untaintB= &is_tainted($p_dir)
ABresult
0X0
100
111
338 0 ( $udir ) = $p_dir =~ m|$untaint_pat|;
339 0 ▶ unless (defined $udir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $udir) 0 0 0
340 0 ▶ if ($untaint_skip == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::untaint_skip == 0) { } 0 0 0
341 0 die "directory $p_dir is still tainted";
342 }
343 else {
344 0 return;
345 }
346 }
347 }
348 0 ▶ unless (chdir ($Is_VMS && $udir !~ /[\/\[<]+/ ? "./$udir" : $udir)) {
Branch: 2 branches
BranchTrueFalseTotal
unless (chdir($Is_VMS && !($udir =~ m([/\[<]+)) ? "./$udir" : $udir)) 0 0 0
$Is_VMS && !($udir =~ m([/\[<]+)) ? : 0 0 0
Condition0%0/3
$Is_VMS and not $udir =~ m([/\[<]+)
!ll&&!rl&&r
000
MC/DC0%0/2
$Is_VMS and not $udir =~ m([/\[<]+)
$Is_VMS not $udir =~ m([/\[<]+)
Truth table0%0/3
A and not(B)
A= $Is_VMSB= not $udir =~ m([/\[<]+)
ABresult
0X0
100
111
349 0 warnings::warnif "Can't cd to $udir: $!\n";
350 0 return;
351 }
352 }
353  
354 # push the starting directory
355 0 ▶ push @Stack,[$CdLvl,$p_dir,$dir_rel,-1] if $bydepth;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::bydepth 0 0 0
356  
357 0 ▶ while (defined $SE) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $SE) 0 0 0
358 0 ▶ unless ($bydepth) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($File::Find::bydepth) 0 0 0
359 0 $dir= $p_dir; # $File::Find::dir
360 0 $name= $dir_name; # $File::Find::name
361 0 ▶ $_= ($no_chdir ? $dir_name : $dir_rel ); # $_
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::no_chdir ? : 0 0 0
362 # prune may happen here
363 0 $prune= 0;
364 0 { $wanted_callback->() }; # protect against wild "next"
365 0 ▶ next if $prune;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::prune 0 0 0
366 }
367  
368 # change to that directory
369 0 ▶ unless ($no_chdir || ($dir_rel eq $File::Find::current_dir)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($File::Find::no_chdir or $dir_rel eq $File::Find::current_dir) 0 0 0
Condition0%0/3
$File::Find::no_chdir or $dir_rel eq $File::Find::current_dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$File::Find::no_chdir or $dir_rel eq $File::Find::current_dir
$File::Find::no_chdir $dir_rel eq $File::Find::current_dir
Truth table0%0/3
A or B
A= $File::Find::no_chdirB= $dir_rel eq $File::Find::current_dir
ABresult
1X1
011
000
370 0 my $udir= $dir_rel;
371 0 ▶ if ( ($untaint) && (($tainted) || ($tainted = is_tainted($dir_rel) )) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::untaint and $tainted || ($tainted = &is_tainted($dir_rel))) 0 0 0
Condition0%0/6
$File::Find::untaint and $tainted || ($tainted = &is_tainted($dir_rel))
!ll&&!rl&&r
000
$tainted or $tainted = &is_tainted($dir_rel)
l!l&&r!l&&!r
000
MC/DC0%0/3
$File::Find::untaint and $tainted || ($tainted = &is_tainted($dir_rel))
$File::Find::untaint $tainted $tainted = &is_tainted($dir_rel)
Truth table0%0/4
A and B or C
A= $File::Find::untaintB= $taintedC= $tainted = &is_tainted($dir_rel)
ABCresult
0XX0
1000
11X1
1011
372 0 ( $udir ) = $dir_rel =~ m|$untaint_pat|;
373 0 ▶ unless (defined $udir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $udir) 0 0 0
374 0 ▶ if ($untaint_skip == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::untaint_skip == 0) { } 0 0 0
375 0 ▶ die "directory (" . ($p_dir ne '/' ? $p_dir : '') . "/) $dir_rel is still tainted";
Branch: 1 branch
BranchTrueFalseTotal
$p_dir ne '/' ? : 0 0 0
376 } else { # $untaint_skip == 1
377 0 next;
378 }
379 }
380 }
381 0 ▶ unless (chdir ($Is_VMS && $udir !~ /[\/\[<]+/ ? "./$udir" : $udir)) {
Branch: 2 branches
BranchTrueFalseTotal
unless (chdir($Is_VMS && !($udir =~ m([/\[<]+)) ? "./$udir" : $udir)) 0 0 0
$Is_VMS && !($udir =~ m([/\[<]+)) ? : 0 0 0
Condition0%0/3
$Is_VMS and not $udir =~ m([/\[<]+)
!ll&&!rl&&r
000
MC/DC0%0/2
$Is_VMS and not $udir =~ m([/\[<]+)
$Is_VMS not $udir =~ m([/\[<]+)
Truth table0%0/3
A and not(B)
A= $Is_VMSB= not $udir =~ m([/\[<]+)
ABresult
0X0
100
111
382 0 ▶ warnings::warnif "Can't cd to (" .
Branch: 1 branch
BranchTrueFalseTotal
$p_dir ne '/' ? : 0 0 0
383 ($p_dir ne '/' ? $p_dir : '') . "/) $udir: $!\n";
384 0 next;
385 }
386 0 $CdLvl++;
387 }
388  
389 0 $dir= $dir_name; # $File::Find::dir
390  
391 # Get the list of files in the current directory.
392 0 my $dh;
393 0 ▶ unless (opendir $dh, ($no_chdir ? $dir_name : $File::Find::current_dir)) {
Branch: 2 branches
BranchTrueFalseTotal
unless (opendir $dh, $File::Find::no_chdir ? $dir_name : $File::Find::current_dir) 0 0 0
$File::Find::no_chdir ? : 0 0 0
394 0 warnings::warnif "Can't opendir($dir_name): $!\n";
395 0 next;
396 }
397 0 @filenames = readdir $dh;
398 0 closedir($dh);
399 0 ▶ @filenames = $pre_process->(@filenames) if $pre_process;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::pre_process 0 0 0
400 0 ▶ push @Stack,[$CdLvl,$dir_name,"",-2] if $post_process;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::post_process 0 0 0
401  
402 # default: use whatever was specified
403 # (if $nlink >= 2, and $avoid_nlink == 0, this will switch back)
404 0 $no_nlink = $avoid_nlink;
405 # if dir has wrong nlink count, force switch to slower stat method
406 0 ▶ $no_nlink = 1 if ($nlink < 2);
Branch: 1 branch
BranchTrueFalseTotal
if $nlink < 2 0 0 0
407  
408 0 ▶ if ($nlink == 2 && !$no_nlink) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nlink == 2 and not $no_nlink) { } 0 0 0
Condition0%0/3
$nlink == 2 and not $no_nlink
!ll&&!rl&&r
000
MC/DC0%0/2
$nlink == 2 and not $no_nlink
$nlink == 2 not $no_nlink
Truth table0%0/3
A and not(B)
A= $nlink == 2B= not $no_nlink
ABresult
0X0
100
111
409 # This dir has no subdirectories.
410 0 for my $FN (@filenames) {
411 0 ▶ if ($Is_VMS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS) 0 0 0
412 # Big hammer here - Compensate for VMS trailing . and .dir
413 # No win situation until this is changed, but this
414 # will handle the majority of the cases with breaking the fewest
415  
416 0 $FN =~ s/\.dir\z//i;
417 0 ▶ $FN =~ s#\.$## if ($FN ne '.');
Branch: 1 branch
BranchTrueFalseTotal
if $FN ne "." 0 0 0
418 }
419 0 ▶ next if $FN =~ $File::Find::skip_pattern;
Branch: 1 branch
BranchTrueFalseTotal
if $FN =~ /$File::Find::skip_pattern/ 0 0 0
420  
421 0 $name = $dir_pref . $FN; # $File::Find::name
422 0 ▶ $_ = ($no_chdir ? $name : $FN); # $_
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::no_chdir ? : 0 0 0
423 0 { $wanted_callback->() }; # protect against wild "next"
424 }
425  
426 }
427 else {
428 # This dir has subdirectories.
429 0 $subcount = $nlink - 2;
430  
431 # HACK: insert directories at this position, so as to preserve
432 # the user pre-processed ordering of files (thus ensuring
433 # directory traversal is in user sorted order, not at random).
434 0 my $stack_top = @Stack;
435  
436 0 for my $FN (@filenames) {
437 0 ▶ next if $FN =~ $File::Find::skip_pattern;
Branch: 1 branch
BranchTrueFalseTotal
if $FN =~ /$File::Find::skip_pattern/ 0 0 0
438 0 ▶ if ($subcount > 0 || $no_nlink) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subcount > 0 or $no_nlink) { } 0 0 0
Condition0%0/3
$subcount > 0 or $no_nlink
l!l&&r!l&&!r
000
MC/DC0%0/2
$subcount > 0 or $no_nlink
$subcount > 0 $no_nlink
Truth table0%0/3
A or B
A= $subcount > 0B= $no_nlink
ABresult
1X1
011
000
439 # Seen all the subdirs?
440 # check for directoriness.
441 # stat is faster for a file in the current directory
442 0 ▶ $sub_nlink = (lstat ($no_chdir ? $dir_pref . $FN : $FN))[3];
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::no_chdir ? : 0 0 0
443  
444 0 ▶ if (-d _) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d _) { } 0 0 0
445 0 --$subcount;
446 0 ▶ $FN =~ s/\.dir\z//i if $Is_VMS;
Branch: 1 branch
BranchTrueFalseTotal
if $Is_VMS 0 0 0
447 # HACK: replace push to preserve dir traversal order
448 #push @Stack,[$CdLvl,$dir_name,$FN,$sub_nlink];
449 0 splice @Stack, $stack_top, 0,
450 [$CdLvl,$dir_name,$FN,$sub_nlink];
451 }
452 else {
453 0 $name = $dir_pref . $FN; # $File::Find::name
454 0 ▶ $_= ($no_chdir ? $name : $FN); # $_
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::no_chdir ? : 0 0 0
455 0 { $wanted_callback->() }; # protect against wild "next"
456 }
457 }
458 else {
459 0 $name = $dir_pref . $FN; # $File::Find::name
460 0 ▶ $_= ($no_chdir ? $name : $FN); # $_
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::no_chdir ? : 0 0 0
461 0 { $wanted_callback->() }; # protect against wild "next"
462 }
463 }
464 }
465 }
466 continue {
467 0 ▶ while ( defined ($SE = pop @Stack) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($SE = pop @Stack)) 0 0 0
468 0 ($Level, $p_dir, $dir_rel, $nlink) = @$SE;
469 0 ▶ if ($CdLvl > $Level && !$no_chdir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CdLvl > $Level and not $File::Find::no_chdir) 0 0 0
Condition0%0/3
$CdLvl > $Level and not $File::Find::no_chdir
!ll&&!rl&&r
000
MC/DC0%0/2
$CdLvl > $Level and not $File::Find::no_chdir
$CdLvl > $Level not $File::Find::no_chdir
Truth table0%0/3
A and not(B)
A= $CdLvl > $LevelB= not $File::Find::no_chdir
ABresult
0X0
100
111
470 0 my $tmp;
471 0 ▶ if ($Is_VMS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS) { } 0 0 0
472 0 $tmp = '[' . ('-' x ($CdLvl-$Level)) . ']';
473 }
474 else {
475 0 $tmp = join('/',('..') x ($CdLvl-$Level));
476 }
477 0 ▶ die "Can't cd to $tmp from $dir_name: $!"
Branch: 1 branch
BranchTrueFalseTotal
unless chdir $tmp 0 0 0
478 unless chdir ($tmp);
479 0 $CdLvl = $Level;
480 }
481  
482 0 ▶ if ($^O eq 'VMS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'VMS') { } 0 0 0
483 0 ▶ if ($p_dir =~ m/[\]>]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p_dir =~ /[\]>]+$/) { } 0 0 0
484 0 $dir_name = $p_dir;
485 0 $dir_name =~ s/([\]>]+)$/.$dir_rel$1/;
486 0 $dir_pref = $dir_name;
487 }
488 else {
489 0 $dir_name = "$p_dir/$dir_rel";
490 0 $dir_pref = "$dir_name/";
491 }
492 }
493 else {
494 0 ▶ $dir_name = _is_root($p_dir) ? "$p_dir$dir_rel" : "$p_dir/$dir_rel";
Branch: 1 branch
BranchTrueFalseTotal
_is_root($p_dir) ? : 0 0 0
495 0 $dir_pref = "$dir_name/";
496 }
497  
498 0 ▶ if ( $nlink == -2 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nlink == -2) { } 0 0 0
elsif ($nlink < 0) { } 0 0 0
499 0 $name = $dir = $p_dir; # $File::Find::name / dir
500 0 $_ = $File::Find::current_dir;
501 0 $post_process->(); # End-of-directory processing
502 }
503 elsif ( $nlink < 0 ) { # must be finddepth, report dirname now
504 0 $name = $dir_name;
505 0 ▶ if ( substr($name,-2) eq '/.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($File::Find::name, -2) eq "/.") 0 0 0
506 0 ▶ substr($name, length($name) == 2 ? -1 : -2) = '';
Branch: 1 branch
BranchTrueFalseTotal
length $File::Find::name == 2 ? : 0 0 0
507 }
508 0 $dir = $p_dir;
509 0 ▶ $_ = ($no_chdir ? $dir_name : $dir_rel );
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::no_chdir ? : 0 0 0
510 0 ▶ if ( substr($_,-2) eq '/.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_, -2) eq "/.") 0 0 0
511 0 ▶ substr($_, length($_) == 2 ? -1 : -2) = '';
Branch: 1 branch
BranchTrueFalseTotal
length $_ == 2 ? : 0 0 0
512 }
513 0 { $wanted_callback->() }; # protect against wild "next"
514 }
515 else {
516 0 ▶ push @Stack,[$CdLvl,$p_dir,$dir_rel,-1] if $bydepth;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::bydepth 0 0 0
517 0 last;
518 }
519 }
520 }
521 }
522  
523  
524 # API:
525 # $wanted
526 # $dir_loc : absolute location of a dir
527 # $p_dir : "parent directory"
528 # preconditions:
529 # chdir (if not no_chdir) to dir
530  
531 sub _find_dir_symlnk($$$) {
532 0 ▶ my ($wanted, $dir_loc, $p_dir) = @_; # $dir_loc is the absolute directory
Subroutine _find_dir_symlnk: not called CC=53 SCAR=79.6
533 0 my @Stack;
534 my @filenames;
535 0 my $new_loc;
536 0 my $updir_loc = $dir_loc; # untainted parent directory
537 0 my $SE = [];
538 0 my $dir_name = $p_dir;
539 0 my $dir_pref;
540 my $loc_pref;
541 0 my $dir_rel = $File::Find::current_dir;
542 0 my $byd_flag; # flag for pending stack entry if $bydepth
543 0 my $tainted = 0;
544 0 my $ok = 1;
545  
546 0 ▶ $dir_pref = _is_root($p_dir) ? $p_dir : "$p_dir/";
Branch: 1 branch
BranchTrueFalseTotal
_is_root($p_dir) ? : 0 0 0
547 0 ▶ $loc_pref = _is_root($dir_loc) ? $dir_loc : "$dir_loc/";
Branch: 1 branch
BranchTrueFalseTotal
_is_root($dir_loc) ? : 0 0 0
548  
549 0 local ($dir, $name, $fullname, $prune);
550  
551 0 ▶ unless ($no_chdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($File::Find::no_chdir) 0 0 0
552 # untaint the topdir
553 0 ▶ if (( $untaint ) && (is_tainted($dir_loc) )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::untaint and &is_tainted($dir_loc)) 0 0 0
Condition0%0/3
$File::Find::untaint and &is_tainted($dir_loc)
!ll&&!rl&&r
000
MC/DC0%0/2
$File::Find::untaint and &is_tainted($dir_loc)
$File::Find::untaint &is_tainted($dir_loc)
Truth table0%0/3
A and B
A= $File::Find::untaintB= &is_tainted($dir_loc)
ABresult
0X0
100
111
554 0 ( $updir_loc ) = $dir_loc =~ m|$untaint_pat|; # parent dir, now untainted
555 # once untainted, $updir_loc is pushed on the stack (as parent directory);
556 # hence, we don't need to untaint the parent directory every time we chdir
557 # to it later
558 0 ▶ unless (defined $updir_loc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $updir_loc) 0 0 0
559 0 ▶ if ($untaint_skip == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::untaint_skip == 0) { } 0 0 0
560 0 die "directory $dir_loc is still tainted";
561 }
562 else {
563 0 return;
564 }
565 }
566 }
567 0 ▶ $ok = chdir($updir_loc) unless ($p_dir eq $File::Find::current_dir);
Branch: 1 branch
BranchTrueFalseTotal
unless $p_dir eq $File::Find::current_dir 0 0 0
568 0 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
569 0 warnings::warnif "Can't cd to $updir_loc: $!\n";
570 0 return;
571 }
572 }
573  
574 0 ▶ push @Stack,[$dir_loc,$updir_loc,$p_dir,$dir_rel,-1] if $bydepth;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::bydepth 0 0 0
575  
576 0 ▶ while (defined $SE) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $SE) 0 0 0
577  
578 0 ▶ unless ($bydepth) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($File::Find::bydepth) 0 0 0
579 # change (back) to parent directory (always untainted)
580 0 ▶ unless ($no_chdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($File::Find::no_chdir) 0 0 0
581 0 ▶ unless (chdir $updir_loc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $updir_loc) 0 0 0
582 0 warnings::warnif "Can't cd to $updir_loc: $!\n";
583 0 next;
584 }
585 }
586 0 $dir= $p_dir; # $File::Find::dir
587 0 $name= $dir_name; # $File::Find::name
588 0 ▶ $_= ($no_chdir ? $dir_name : $dir_rel ); # $_
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::no_chdir ? : 0 0 0
589 0 $fullname= $dir_loc; # $File::Find::fullname
590 # prune may happen here
591 0 $prune= 0;
592 0 lstat($_); # make sure file tests with '_' work
593 0 { $wanted_callback->() }; # protect against wild "next"
594 0 ▶ next if $prune;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::prune 0 0 0
595 }
596  
597 # change to that directory
598 0 ▶ unless ($no_chdir || ($dir_rel eq $File::Find::current_dir)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($File::Find::no_chdir or $dir_rel eq $File::Find::current_dir) 0 0 0
Condition0%0/3
$File::Find::no_chdir or $dir_rel eq $File::Find::current_dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$File::Find::no_chdir or $dir_rel eq $File::Find::current_dir
$File::Find::no_chdir $dir_rel eq $File::Find::current_dir
Truth table0%0/3
A or B
A= $File::Find::no_chdirB= $dir_rel eq $File::Find::current_dir
ABresult
1X1
011
000
599 0 $updir_loc = $dir_loc;
600 0 ▶ if ( ($untaint) && (($tainted) || ($tainted = is_tainted($dir_loc) )) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::untaint and $tainted || ($tainted = &is_tainted($dir_loc))) 0 0 0
Condition0%0/6
$File::Find::untaint and $tainted || ($tainted = &is_tainted($dir_loc))
!ll&&!rl&&r
000
$tainted or $tainted = &is_tainted($dir_loc)
l!l&&r!l&&!r
000
MC/DC0%0/3
$File::Find::untaint and $tainted || ($tainted = &is_tainted($dir_loc))
$File::Find::untaint $tainted $tainted = &is_tainted($dir_loc)
Truth table0%0/4
A and B or C
A= $File::Find::untaintB= $taintedC= $tainted = &is_tainted($dir_loc)
ABCresult
0XX0
1000
11X1
1011
601 # untaint $dir_loc, what will be pushed on the stack as (untainted) parent dir
602 0 ( $updir_loc ) = $dir_loc =~ m|$untaint_pat|;
603 0 ▶ unless (defined $updir_loc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $updir_loc) 0 0 0
604 0 ▶ if ($untaint_skip == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Find::untaint_skip == 0) { } 0 0 0
605 0 die "directory $dir_loc is still tainted";
606 }
607 else {
608 0 next;
609 }
610 }
611 }
612 0 ▶ unless (chdir $updir_loc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $updir_loc) 0 0 0
613 0 warnings::warnif "Can't cd to $updir_loc: $!\n";
614 0 next;
615 }
616 }
617  
618 0 $dir = $dir_name; # $File::Find::dir
619  
620 # Get the list of files in the current directory.
621 0 my $dh;
622 0 ▶ unless (opendir $dh, ($no_chdir ? $dir_loc : $File::Find::current_dir)) {
Branch: 2 branches
BranchTrueFalseTotal
unless (opendir $dh, $File::Find::no_chdir ? $dir_loc : $File::Find::current_dir) 0 0 0
$File::Find::no_chdir ? : 0 0 0
623 0 warnings::warnif "Can't opendir($dir_loc): $!\n";
624 0 next;
625 }
626 0 @filenames = readdir $dh;
627 0 closedir($dh);
628  
629 0 for my $FN (@filenames) {
630 0 ▶ if ($Is_VMS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS) 0 0 0
631 # Big hammer here - Compensate for VMS trailing . and .dir
632 # No win situation until this is changed, but this
633 # will handle the majority of the cases with breaking the fewest.
634  
635 0 $FN =~ s/\.dir\z//i;
636 0 ▶ $FN =~ s#\.$## if ($FN ne '.');
Branch: 1 branch
BranchTrueFalseTotal
if $FN ne "." 0 0 0
637 }
638 0 ▶ next if $FN =~ $File::Find::skip_pattern;
Branch: 1 branch
BranchTrueFalseTotal
if $FN =~ /$File::Find::skip_pattern/ 0 0 0
639  
640 # follow symbolic links / do an lstat
641 0 $new_loc = Follow_SymLink($loc_pref.$FN);
642  
643 # ignore if invalid symlink
644 0 ▶ unless (defined $new_loc) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_loc) 0 0 0
645 0 ▶ if (!defined -l _ && $dangling_symlinks) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined -l(_) and $File::Find::dangling_symlinks) { } 0 0 0
Condition0%0/3
not defined -l(_) and $File::Find::dangling_symlinks
!ll&&!rl&&r
000
MC/DC0%0/2
not defined -l(_) and $File::Find::dangling_symlinks
not defined -l(_) $File::Find::dangling_symlinks
Truth table0%0/3
not(A) and B
A= not defined -l(_)B= $File::Find::dangling_symlinks
ABresult
0X0
100
111
646 0 $fullname = undef;
647 0 ▶ if (ref $dangling_symlinks eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $File::Find::dangling_symlinks eq 'CODE') { } 0 0 0
648 0 $dangling_symlinks->($FN, $dir_pref);
649 } else {
650 0 warnings::warnif "$dir_pref$FN is a dangling symbolic link\n";
651 }
652 }
653 else {
654 0 $fullname = $loc_pref . $FN;
655 }
656 0 $name = $dir_pref . $FN;
657 0 ▶ $_ = ($no_chdir ? $name : $FN);
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::no_chdir ? : 0 0 0
658 0 { $wanted_callback->() };
659 0 next;
660 }
661  
662 0 ▶ if (-d _) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d _) { } 0 0 0
663 0 ▶ if ($Is_VMS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Is_VMS) 0 0 0
664 0 $FN =~ s/\.dir\z//i;
665 0 ▶ $FN =~ s#\.$## if ($FN ne '.');
Branch: 1 branch
BranchTrueFalseTotal
if $FN ne "." 0 0 0
666 0 $new_loc =~ s/\.dir\z//i;
667 0 ▶ $new_loc =~ s#\.$## if ($new_loc ne '.');
Branch: 1 branch
BranchTrueFalseTotal
if $new_loc ne "." 0 0 0
668 }
669 0 push @Stack,[$new_loc,$updir_loc,$dir_name,$FN,1];
670 }
671 else {
672 0 $fullname = $new_loc; # $File::Find::fullname
673 0 $name = $dir_pref . $FN; # $File::Find::name
674 0 ▶ $_ = ($no_chdir ? $name : $FN); # $_
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::no_chdir ? : 0 0 0
675 0 { $wanted_callback->() }; # protect against wild "next"
676 }
677 }
678  
679 }
680 continue {
681 0 ▶ while (defined($SE = pop @Stack)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($SE = pop @Stack)) 0 0 0
682 0 ($dir_loc, $updir_loc, $p_dir, $dir_rel, $byd_flag) = @$SE;
683 0 ▶ $dir_name = _is_root($p_dir) ? "$p_dir$dir_rel" : "$p_dir/$dir_rel";
Branch: 1 branch
BranchTrueFalseTotal
_is_root($p_dir) ? : 0 0 0
684 0 $dir_pref = "$dir_name/";
685 0 $loc_pref = "$dir_loc/";
686 0 ▶ if ( $byd_flag < 0 ) { # must be finddepth, report dirname now
Branch: 1 branch
BranchTrueFalseTotal
if ($byd_flag < 0) { } 0 0 0
687 0 ▶ unless ($no_chdir || ($dir_rel eq $File::Find::current_dir)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($File::Find::no_chdir or $dir_rel eq $File::Find::current_dir) 0 0 0
Condition0%0/3
$File::Find::no_chdir or $dir_rel eq $File::Find::current_dir
l!l&&r!l&&!r
000
MC/DC0%0/2
$File::Find::no_chdir or $dir_rel eq $File::Find::current_dir
$File::Find::no_chdir $dir_rel eq $File::Find::current_dir
Truth table0%0/3
A or B
A= $File::Find::no_chdirB= $dir_rel eq $File::Find::current_dir
ABresult
1X1
011
000
688 0 ▶ unless (chdir $updir_loc) { # $updir_loc (parent dir) is always untainted
Branch: 1 branch
BranchTrueFalseTotal
unless (chdir $updir_loc) 0 0 0
689 0 warnings::warnif "Can't cd to $updir_loc: $!\n";
690 0 next;
691 }
692 }
693 0 $fullname = $dir_loc; # $File::Find::fullname
694 0 $name = $dir_name; # $File::Find::name
695 0 ▶ if ( substr($name,-2) eq '/.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($File::Find::name, -2) eq "/.") 0 0 0
696 0 ▶ substr($name, length($name) == 2 ? -1 : -2) = ''; # $File::Find::name
Branch: 1 branch
BranchTrueFalseTotal
length $File::Find::name == 2 ? : 0 0 0
697 }
698 0 $dir = $p_dir; # $File::Find::dir
699 0 ▶ $_ = ($no_chdir ? $dir_name : $dir_rel); # $_
Branch: 1 branch
BranchTrueFalseTotal
$File::Find::no_chdir ? : 0 0 0
700 0 ▶ if ( substr($_,-2) eq '/.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_, -2) eq "/.") 0 0 0
701 0 ▶ substr($_, length($_) == 2 ? -1 : -2) = '';
Branch: 1 branch
BranchTrueFalseTotal
length $_ == 2 ? : 0 0 0
702 }
703  
704 0 lstat($_); # make sure file tests with '_' work
705 0 { $wanted_callback->() }; # protect against wild "next"
706 }
707 else {
708 0 ▶ push @Stack,[$dir_loc, $updir_loc, $p_dir, $dir_rel,-1] if $bydepth;
Branch: 1 branch
BranchTrueFalseTotal
if $File::Find::bydepth 0 0 0
709 0 last;
710 }
711 }
712 }
713 }
714  
715  
716 sub wrap_wanted {
717 0 ▶ my $wanted = shift;
Subroutine wrap_wanted: not called CC=14 SCAR=53.5
Pod undocumented
718 0 ▶ if ( ref($wanted) eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $wanted eq 'HASH') { } 0 0 0
elsif (ref $wanted eq 'CODE') { } 0 0 0
719 # RT #122547
720 0 my %valid_options = map {$_ => 1} qw(
721 wanted
722 bydepth
723 preprocess
724 postprocess
725 follow
726 follow_fast
727 follow_skip
728 dangling_symlinks
729 no_chdir
730 untaint
731 untaint_pattern
732 untaint_skip
733 );
734 0 my @invalid_options = ();
735 0 for my $v (keys %{$wanted}) {
736 0 ▶ push @invalid_options, $v unless exists $valid_options{$v};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $valid_options{$v} 0 0 0
737 }
738 0 ▶ warn "Invalid option(s): @invalid_options" if @invalid_options;
Branch: 1 branch
BranchTrueFalseTotal
if @invalid_options 0 0 0
739  
740 0 ▶ unless( exists $wanted->{wanted} and ref( $wanted->{wanted} ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $wanted->{"wanted"} and ref $wanted->{"wanted"} eq "CODE") 0 0 0
Condition0%0/3
exists $wanted->{"wanted"} and ref $wanted->{"wanted"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $wanted->{"wanted"} and ref $wanted->{"wanted"} eq "CODE"
exists $wanted->{"wanted"} ref $wanted->{"wanted"} eq "CODE"
Truth table0%0/3
A and B
A= exists $wanted->{"wanted"}B= ref $wanted->{"wanted"} eq "CODE"
ABresult
0X0
100
111
741 0 die 'no &wanted subroutine given';
742 }
743 0 ▶ if ( $wanted->{follow} || $wanted->{follow_fast}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted->{"follow"} or $wanted->{"follow_fast"}) 0 0 0
Condition0%0/3
$wanted->{"follow"} or $wanted->{"follow_fast"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$wanted->{"follow"} or $wanted->{"follow_fast"}
$wanted->{"follow"} $wanted->{"follow_fast"}
Truth table0%0/3
A or B
A= $wanted->{"follow"}B= $wanted->{"follow_fast"}
ABresult
1X1
011
000
744 0 ▶ $wanted->{follow_skip} = 1 unless defined $wanted->{follow_skip};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wanted->{"follow_skip"} 0 0 0
745 }
746 0 ▶ if ( $wanted->{untaint} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wanted->{"untaint"}) 0 0 0
747 $wanted->{untaint_pattern} = $File::Find::untaint_pattern
748 0 ▶ unless defined $wanted->{untaint_pattern};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wanted->{"untaint_pattern"} 0 0 0
749 0 ▶ $wanted->{untaint_skip} = 0 unless defined $wanted->{untaint_skip};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $wanted->{"untaint_skip"} 0 0 0
750 }
751 0 return $wanted;
752 }
753 elsif( ref( $wanted ) eq 'CODE' ) {
754 0 return { wanted => $wanted };
755 }
756 else {
757 0 die 'no &wanted subroutine given';
758 }
759 }
760  
761 sub find {
762 0 ▶ my $wanted = shift;
Subroutine find: not called CC=1 SCAR=6.9
Pod documented
763 0 _find_opt(wrap_wanted($wanted), @_);
764 }
765  
766 sub finddepth {
767 0 ▶ my $wanted = wrap_wanted(shift);
Subroutine finddepth: not called CC=1 SCAR=6.9
Pod documented
768 0 $wanted->{bydepth} = 1;
769 0 _find_opt($wanted, @_);
770 }
771  
772 # default
773 $File::Find::skip_pattern = qr/^\.{1,2}\z/;
774 $File::Find::untaint_pattern = qr|^([-+@\w./]+)$|;
775  
776 # this _should_ work properly on all platforms
777 # where File::Find can be expected to work
778 $File::Find::current_dir = File::Spec->curdir || '.';
779  
780 $File::Find::dont_use_nlink = 1;
781  
782 # We need a function that checks if a scalar is tainted. Either use the
783 # Scalar::Util module's tainted() function or our (slower) pure Perl
784 # fallback is_tainted_pp()
785 {
786 local $@;
787 eval { require Scalar::Util };
788 *is_tainted = $@ ? \&is_tainted_pp : \&Scalar::Util::tainted;
789 }
790  
791 1;
792  
793 __END__
↑ Summary /usr/local/lib/perl5/5.44.0/IO/Socket/IP.pm »