lib/File/Pairtree.pm

filter: Statementstmt 89.6% 233 / 260 Branchbran 59.4% 82 / 138 Conditioncond 48.2% 41 / 85 MC/DCmcdc 10.2% 5 / 49 Subroutinesub 92.5% 25 / 27 Podpod 0.0% 0 / 14 totaltotal 67.3% 386 / 573 CC 98 SCAR 26.2
CC
98
Cov
74%
pt_rmid
26.9
pt_mkid
25.1
__ANON__
17.1
CRAP 13.7
↑ Summary script/pt »
1 package File::Pairtree;
2  
3 17 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 17 our $VERSION;
8 17 $VERSION = sprintf "%d.%02d", q$Name: Release-1-02 $ =~ /Release-(\d+)-(\d+)/;
9 #$VERSION = sprintf "%s", q$Name: Release-v0.304.0$ =~ /Release-(v\d+\.\d+\.\d+)/;
10 #our $NVERSION; # pure numeric 2-part equivalent version
11 #($NVERSION = $VERSION) =~ s/v(\d+\.\d+)\.\d+/$1/;
12  
13 17 require Exporter;
14 17 our @ISA = qw(Exporter);
15  
16 17 our @EXPORT = qw();
17 17 our @EXPORT_OK = qw(
18 id2ppath ppath2id s2ppchars id2pairpath pairpath2id
19 pt_lsid pt_lstree pt_mkid pt_mktree pt_rmid
20 pt_budstr get_prefix
21 $pfixtail
22 $pair $pairp1 $pairm1
23 );
24 17 our %EXPORT_TAGS = (all => [ @EXPORT_OK ]);
25  
26 17 our @EXPORT_FAIL = qw(
27 pair=1 pair=2 pair=3 pair=4 pair=5 pair=6 pair=7 pair=8 pair=9
28 );
29 17 push @EXPORT_OK, @EXPORT_FAIL; # add pseudo-symbols we will trap
30  
31 # This is a magic routine that the Exporter calls for any unknown symbols.
32 # We use it to permit export of pseudo-symbols "pair=1", "pair=2", ...,
33 # "pair=9" so the caller can define a pair to mean 1, 2, ..., or 9 octets.
34 #
35 0 ▶sub export_fail { my( $class, @symbols )=@_;
Subroutine export_fail: not called CC=3 SCAR=24.8
Pod undocumented
36  
37 0 my @unknowns;
38 0 for (@symbols) {
39 0 ▶ ! s/^pair=([1-9])$/$1/ and
Branch: 1 branch
BranchTrueFalseTotal
s/^pair=([1-9])$/$1/ or push(@unknowns, $_), next 0 0 0
40 push(@unknowns, $_),
41 next;
42 0 pair_means($_); # define how many octets form a pair
43 }
44 0 return @unknowns;
45 }
46  
47 # xxx Config?
48 17 my $default_pathcomp_sep = '/';
49  
50 # In case we want to experiment with different cardinality of "pair",
51 # eg, 3 chars, 1 char, 4 chars. This is mostly untested. XXX
52 #
53 17 our ($pair, $pairp1, $pairm1);
54  
55 17 ▶sub pair_means{ my( $n )=@_;
Subroutine pair_means: called CC=2 SCAR=7.0
Pod undocumented
56  
57 17 ▶ die "the number meant by 'pair' must be a positive integer"
Branch: 1 branch
BranchTrueFalseTotal
if $n < 1 0 17 17
58 if ($n < 1);
59 17 $pair = $n;
60 17 $pairp1 = $pair + 1;
61 17 $pairm1 = $pair - 1; # xxx what if $pairm1 is zero?
62 17 return 1;
63 }
64 # XXXXXXXX arrange to call this at compile time?? punish the user if
65 # they call it themselves???
66  
67 # If not done so on import, define now how many octets in a pair.
68 #
69 17 ▶defined($pair) or pair_means(2);
Branch: 1 branch
BranchTrueFalseTotal
defined $File::Pairtree::pair or pair_means(2) 0 17 17
70 #
71 # Now it's safe to define compiled regexps based on
72 # constant values for $pair, $pairp1, and $pairm1.
73  
74 # this regexp matches a valid base ppath with bud attached
75 17 our $proper_ppath_re = "([^/]{$pair}/)*[^/]{1,$pair}";
76 17 our $root = "pairtree_root";
77  
78 17 my $R = $root;
79 17 my $P = $proper_ppath_re;
80  
81 # Pairtree - Pairtree support software (Perl module)
82 #
83 # Author: John A. Kunze, jak@ucop.edu, California Digital Library, 2008
84 # based on three lines of code originally from Sebastien Korner:
85 # $pt_objid =~ s/(\"|\*|\+|,|<|=|>|\?|\^|\|)/sprintf("^%x", ord($1))/eg;
86 # $pt_objid =~ tr/\/:./=+,/;
87 # my $pt_prefix = $namespace."/pairtree_root/".join('/', $pt_objid =~ /..|.$/g);
88  
89 # id2ppath - return /-terminated ppath corresponding to id
90 #
91 # For Perl, the platform's path component separator ('/' or '\') is
92 # automagically converted when needed to do filesystem things; in fact,
93 # trying to use the correct separator can get you into trouble. So we
94 # make it possible to specify the path component separator, but we won't
95 # do it for you. Instead we assume '/'.
96 #
97 # The return path starts with /pairtree_root to encourage good habits --
98 # this could backfire. We use the symbol 'pathcomp_sep' because
99 # 'path_sep' is already taken by the Config module to designate the
100 # character that separates entire pathnames, eg, ':' in the PATH
101 # environment variable.
102 #
103 # XXXXX this $pathcomp_sep -- is it worth a variable or is it better to
104 # let it be constant so we can compile the regexp?
105 46 ▶sub id2ppath{ my( $id, $pathcomp_sep )=@_; # single arg form, second
Subroutine id2ppath: called CC=2 SCAR=7.0
Pod undocumented
106 # arg not advertized
107  
108 46 ▶ $pathcomp_sep ||= $default_pathcomp_sep;
Condition66%2/3
$pathcomp_sep ||= $default_pathcomp_sep
l!l&&r!l&&!r
1450
MC/DC0%0/2
$pathcomp_sep ||= $default_pathcomp_sep
$pathcomp_sep $default_pathcomp_sep
Truth table66%2/3
A ||= B
A= $pathcomp_sepB= $default_pathcomp_sep
ABresult
1X1
011
000
109 # $id =~ s{
110 # (["*+,<=>?\\^|] # some visible ASCII and
111 # |[^\x21-\x7e]) # all non-visible ASCII
112 # }{
113 # sprintf("^%02x", ord($1)) # replacement hex code
114 # }xeg;
115 #
116 # # Now do the single-char to single-char mapping.
117 # # The / translated next is not to be confused with $pathcomp_sep.
118 # #
119 # $id =~ tr /\/:./=+,/; # per spec, /:. become =+,
120  
121 46 $id = s2ppchars($id, $pathcomp_sep);
122  
123 46 return $root
124 . $pathcomp_sep
125 . join($pathcomp_sep, $id =~ /.{1,$pair}/g)
126 . $pathcomp_sep;
127 # . join($pathcomp_sep, $id =~ /..|.$/g)
128 }
129  
130 57 ▶sub s2ppchars{ my( $s, $pathcomp_sep )=@_;
Subroutine s2ppchars: called CC=2 SCAR=7.0
Pod undocumented
131  
132 57 ▶ $pathcomp_sep ||= $default_pathcomp_sep;
Condition66%2/3
$pathcomp_sep ||= $default_pathcomp_sep
l!l&&r!l&&!r
46110
MC/DC0%0/2
$pathcomp_sep ||= $default_pathcomp_sep
$pathcomp_sep $default_pathcomp_sep
Truth table66%2/3
A ||= B
A= $pathcomp_sepB= $default_pathcomp_sep
ABresult
1X1
011
000
133 57 $s =~ s{
134 (["*+,<=>?\\^|] # some visible ASCII and
135 |[^\x21-\x7e]) # all non-visible ASCII
136 }{
137 118 sprintf("^%02x", ord($1)) # replacement hex code
138 }xeg;
139  
140 # Now do the single-char to single-char mapping.
141 # The / translated next is not to be confused with $pathcomp_sep.
142 #
143 57 $s =~ tr /\/:./=+,/; # per spec, /:. become =+,
144 57 return $s;
145 }
146  
147 # XXX ditch 2-arg forms?
148 # This 2-arg form exists for parallelism with other language interfaces
149 # (that don't may not have optional arguments). Perl users would
150 # normally prefer the id2ppath form for full functionality and speed.
151 #
152 0 ▶sub id2pairpath{ my( $id, $pathcomp_sep )=@_; # two-argument form
Subroutine id2pairpath: not called CC=1 SCAR=6.9
Pod undocumented
153  
154 0 return id2ppath($id, $pathcomp_sep);
155 }
156  
157 # ppath2id - return id corresponding to ppath, or string of the form
158 # "error: <msg>"
159 # There is more error checking required for ppath2id than id2ppath,
160 # as the domain is more constrained.
161 #
162 49 ▶sub ppath2id{ my( $path, $pathcomp_sep )=@_; # single arg form, second
Subroutine ppath2id: called CC=6 SCAR=17.9
Pod undocumented
163 # arg not advertized
164 49 my $id = $path; # initialize $id with $path
165 49 ▶ my $p = $pathcomp_sep || $default_pathcomp_sep;
Condition66%2/3
$pathcomp_sep || $default_pathcomp_sep
l!l&&r!l&&!r
1480
MC/DC0%0/2
$pathcomp_sep || $default_pathcomp_sep
$pathcomp_sep $default_pathcomp_sep
Truth table66%2/3
A || B
A= $pathcomp_sepB= $default_pathcomp_sep
ABresult
1X1
011
000
166  
167 49 my $expect_hexenc; # chars expected to be hex encoded
168 49 ▶ if ($p eq '\\') { # \ is a common, problemmatic case
Branch: 1 branch
BranchTrueFalseTotal
if ($p eq '\\') { } 1 48 49
169 1 $expect_hexenc = '"*<>?|'; # don't need to encode \
170 1 $p = '\\\\'; # and double escape for use in regex
171 } else {
172 48 $expect_hexenc = '"*<>?|\\\\'; # do need to encode \
173 }
174  
175 # Trim everything from the beginning up to the last instance of
176 # $root (via a greedy match). If there's a pairpath to the right
177 # of a given pairpath, assume that the most fine grained path
178 # (rightmost) is the one the user's interested in.
179 #
180 49 $id =~ s/^.*$root//;
181  
182 # Normalize so there's no initial or final whitespace, no
183 # repeated $pathcomp_sep chars, and exactly one $pathcomp_sep
184 # at the beginning and end.
185 #
186 49 $id =~ s/^\s*/$p/;
187 49 $id =~ s/\s*$/$p/;
188 49 $id =~ s/$p+/$p/g;
189  
190 # Also trim any final junk, eg, anpath extension that is really
191 # internal to an object directory.
192 #
193 49 $id =~ s/[^$p]{$pairp1,}.*$//; # trim final junk
194  
195 # Finally, trim anything that follows a one-char path component,
196 # a one-char component being another signal of the end of a ppath.
197 # In a general sense, "one" here really means "one less than the
198 # number of chars in a 'pair'".
199 #
200 49 $id =~ s/($p([^$p]){1,$pairm1}$p).*$/$1/; # trim after 1-char comp.
201  
202 # Reject if there are any non-visible chars.
203 #
204 49 ▶ return "error: non-visible chars in $path" if
Branch: 1 branch
BranchTrueFalseTotal
if $id =~ /[^\x21-\x7e]/ 1 48 49
205 $id =~ /[^\x21-\x7e]/;
206  
207 # Reject if there are any other chars that should be hex-encoded.
208 #
209 48 ▶ return "error: found chars expected to be hex-encoded in $path" if
Branch: 1 branch
BranchTrueFalseTotal
if $id =~ /[$expect_hexenc]/ 0 48 48
210 $id =~ /[$expect_hexenc]/;
211  
212 # Now remove the path component separators.
213 #
214 48 $id =~ s/$p//g;
215  
216 # Reverse the single-char to single-char mapping.
217 # This might add formerly hex-encoded chars back in.
218 #
219 48 $id =~ tr /=+,/\/:./; # per spec, =+, become /:.
220  
221 # Reject if there are any ^'s not followed by two hex digits.
222 #
223 48 ▶ return "error: impossible hex-encoding in $path" if
Branch: 1 branch
BranchTrueFalseTotal
if $id =~ /\^($|.$|[^0-9a-fA-F].|.[^0-9a-fA-F])/ 4 44 48
224 $id =~ /\^($|.$|[^0-9a-fA-F].|.[^0-9a-fA-F])/;
225  
226 # Now reverse the hex conversion.
227 #
228 44 $id =~ s{
229 \^([0-9a-fA-F]{2})
230 }{
231 118 chr(hex("0x"."$1"))
232 }xeg;
233  
234 44 return $id;
235 }
236  
237 17 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
238 17 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
239 17 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
240 17 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
241 17 ▶use File::Namaste qw( nam_add );
Subroutine BEGIN: called CC=1 SCAR=0.0
242 17 ▶use File::Value ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
243 17 ▶use File::Glob ':glob'; # standard use of module, which we need
Subroutine BEGIN: called CC=1 SCAR=0.0
244 # as vanilla glob won't match whitespace
245  
246 17 our $Win; # whether we're running on Windows
247 # xxx should probably test directly for symlink capacity
248 17 ▶defined($Win) or # if we're on a Windows platform avoid -l
Branch: 1 branch
BranchTrueFalseTotal
defined $File::Pairtree::Win or $File::Pairtree::Win = grep(/Win32|OS2/i, @File::Spec::ISA) 0 17 17
249 $Win = grep(/Win32|OS2/i, @File::Spec::ISA);
250  
251 17 my $pfixtail = 'pairtree_prefix';
252  
253 # Return empty string unless we find a prefix value.
254 22 ▶sub get_prefix { my( $parent_dir )=@_;
Subroutine get_prefix: called CC=3 SCAR=11.0
Pod undocumented
255  
256 22 my $prefix = "";
257 22 my $pxfile = $parent_dir . $pfixtail;
258 22 ▶ return $prefix unless -e $pxfile;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $pxfile 15 7 22
259 7 my $msg = file_value("< $pxfile", $prefix);
260 7 ▶ die "$pxfile: $msg" if $msg;
Branch: 1 branch
BranchTrueFalseTotal
if $msg 0 7 7
261 7 return $prefix;
262 }
263  
264 # caller can define inputs $$r_opt{prefix} and $$r_opt{parent_dir} for speed
265 # we return under keys: msg, ppath, bud
266 # return 0 on success, 1 on soft fail, >1 on hard fail
267 # xxxxxxxxx get consistent on these return codes/croaks
268 #
269 5 ▶sub pt_lsid { my( $dir, $id, $r_opt )=@_;
Subroutine pt_lsid: called CC=12 SCAR=26.3
Pod undocumented
270  
271 5 ▶ $dir or croak "no dir or empty dir";
Branch: 1 branch
BranchTrueFalseTotal
$dir or croak("no dir or empty dir") 5 0 5
272 5 ▶ $id or croak "no id or empty id";
Branch: 1 branch
BranchTrueFalseTotal
$id or croak("no id or empty id") 5 0 5
273 5 ▶ ref($r_opt) eq "HASH" or
Branch: 1 branch
BranchTrueFalseTotal
ref $r_opt eq "HASH" or croak("r_opt must reference a hash (for input/output)") 5 0 5
274 croak "r_opt must reference a hash (for input/output)";
275  
276 5 $dir = fiso_dname($dir, $R); # make sure we have descender
277 my $parent_dir = $$r_opt{parent_dir}
278 5 ▶ || fiso_uname($dir);
Condition33%1/3
$r_opt->{'parent_dir'} || fiso_uname($dir)
l!l&&r!l&&!r
500
MC/DC0%0/2
$r_opt->{'parent_dir'} || fiso_uname($dir)
$r_opt->{'parent_dir'} fiso_uname($dir)
Truth table33%1/3
A || B
A= $r_opt->{'parent_dir'}B= fiso_uname($dir)
ABresult
1X1
011
000
279 my $prefix = $$r_opt{prefix}
280 5 ▶ || get_prefix($parent_dir);
Condition33%1/3
$r_opt->{'prefix'} || get_prefix($parent_dir)
l!l&&r!l&&!r
500
MC/DC0%0/2
$r_opt->{'prefix'} || get_prefix($parent_dir)
$r_opt->{'prefix'} get_prefix($parent_dir)
Truth table33%1/3
A || B
A= $r_opt->{'prefix'}B= get_prefix($parent_dir)
ABresult
1X1
011
000
281  
282 # prefix substitution is optional unless -f ??? XXXXX
283 # xxx test
284 $prefix and ! ($id =~ s/^$prefix//) and $$r_opt{force} and
285 5 ▶ ($$r_opt{msg} = "no prefix present in: $id"),
Branch: 1 branch
BranchTrueFalseTotal
$prefix and not $id =~ s/^$prefix// and $r_opt->{"force"} and $r_opt->{"msg"} = "no prefix present in: $id", (return 2) 1 4 5
Condition83%5/6
$prefix and not $id =~ s/^$prefix// and $r_opt->{"force"}
!ll&&!rl&&r
311
$prefix and not $id =~ s/^$prefix//
!ll&&!rl&&r
032
MC/DC66%2/3
$prefix and not $id =~ s/^$prefix// and $r_opt->{"force"}
$prefix not $id =~ s/^$prefix// $r_opt->{"force"}
Truth table75%3/4
A and not(B) and C
A= $prefixB= not $id =~ s/^$prefix//C= $r_opt->{"force"}
ABCresult
0XX0
10X0
1100
1111
286 return 2;
287  
288 4 my $ppath = $parent_dir . id2ppath($id);
289 -e $ppath or
290 ($$r_opt{msg} = "non-existent ppath ($ppath)"),
291 4 ▶ ($$r_opt{ppath} = ""),
Branch: 1 branch
BranchTrueFalseTotal
-e $ppath or $r_opt->{"msg"} = "non-existent ppath ($ppath)", $r_opt->{"ppath"} = "", (return 1) 3 1 4
292 return 1; # softer failure than return 2
293 3 $$r_opt{ppath} = $ppath;
294  
295 # Now that we have a valid ppath, we still don't know what
296 # the encapsulating directory (or anything else for that
297 # matter) looks like, so we use glob to look for things.
298 # Recall that $ppath ends in a '/' (from id2ppath).
299 # xxx sepchar better than / ?
300 #
301 3 my @buds = grep ! m{(^|/)\.\.?$}, # except for . and ..
302 bsd_glob($ppath . "{*,.*}"); # look for all files
303 3 my $nbuds = scalar @buds; # how many buds?
304 $nbuds == 0 and # empty ppath, not a node
305 ($$r_opt{msg} = "no bud: $ppath"),
306 3 ▶ ($$r_opt{bud} = ""),
Branch: 1 branch
BranchTrueFalseTotal
$nbuds == 0 and $r_opt->{"msg"} = "no bud: $ppath", $r_opt->{"bud"} = "", (return 2) 0 3 3
307 return 2;
308  
309 # If we get here, there's one or more things at end of ppath.
310 #
311 $nbuds > 1 and
312 ($$r_opt{msg} = "expected one bud but got $nbuds buds"),
313 3 ▶ ($$r_opt{bud} = join " ", @buds),
Branch: 1 branch
BranchTrueFalseTotal
$nbuds > 1 and $r_opt->{"msg"} = "expected one bud but got $nbuds buds", $r_opt->{"bud"} = join(" ", @buds), (return 2) 0 3 3
314 return 2;
315  
316 # If we get here, only one thing at end of ppath (the common case).
317 #
318 3 $$r_opt{bud} = shift @buds;
319  
320 # XXXXX ??? $$r_opt{oxum}, $$r_opt{details} ? $$r_opt{long}
321 # ? $$r_opt{all}
322 3 return 0;
323 }
324  
325 17 my $homily = "(pairpath end should be followed by only one thing -- " .
326 "a directory name more than $pair characters long)";
327  
328 # Create a closure to hold a stateful node-visiting subroutine and other
329 # options suitable to be passed as the options parameter to File::Find.
330 # Returns the small hash { 'wanted' => $visitor, 'follow' => 1 } and a
331 # subroutine $visit_over that can be called to summarize the visit.
332 #
333 3 ▶sub make_visitor { my( $r_opt )=@_;
Subroutine make_visitor: called CC=2 SCAR=7.2
Pod undocumented
334  
335 my $om = $r_opt->{om} or
336 3 ▶ return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $om = $r_opt->{"om"} or return undef 3 0 3
337  
338 3 my $objectcount = 0; # number of objects encountered
339 3 my $filecount = 0; # number of files encountered xxx
340 3 my $dircount = 0; # number of directories encountered xxx
341 3 my $symlinkcount = 0; # number of symlinks encountered xxx
342 3 my $irregularcount = 0; # non file, non dir fs items to report
343  
344 3 my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $sze);
345 3 my ($pdname, $tpname, $wpname);
346 3 my $symlinks_followed = 1;
347  
348 # yyy do as $curobj = {...}; ?
349 3 my %curobj = (
350 'ppath' => '',
351 'encaperr' => 0,
352 'octets' => 0,
353 'streams' => 0,
354 );
355  
356 # xxx move this outside closure and give it a $currobj arg?
357 # or is this much more efficient as-is?
358 # xxx nail down everything that won't change during lstree
359 17 ▶ my $newobj = sub { my( $ppath, $encaperr, $octets, $streams )=@_;
Subroutine __ANON__: called CC=9 SCAR=24.6
360  
361 # warning: ugly code ahead
362 17 ▶ if ($curobj{'ppath'}) { # print record of previous obj
Branch: 1 branch
BranchTrueFalseTotal
if ($curobj{"ppath"}) 14 3 17
363 14 $_ = ppath2id($curobj{'ppath'});
364 14 s/^/$r_opt->{prefix}/; # uses global set in lstree()
365 $r_opt->{long} and
366 $om->elem('node',
367 14 ▶ join(" ", $_, $curobj{'ppath'},
Branch: 1 branch
BranchTrueFalseTotal
$r_opt->{"long"} and $om->elem("node", join(" ", $_, $curobj{"ppath"}, qq[$curobj{"octets"}.$curobj{"streams"}])), 1 or $om->elem("node", $_), '???' 0 14 14
Condition33%1/3
$r_opt->{"long"} and $om->elem("node", join(" ", $_, $curobj{"ppath"}, qq[$curobj{"octets"}.$curobj{"streams"}])), 1
!ll&&!rl&&r
1400
MC/DC0%0/2
$r_opt->{"long"} and $om->elem("node", join(" ", $_, $curobj{"ppath"}, qq[$curobj{"octets"}.$curobj{"streams"}])), 1
$r_opt->{"long"} $om->elem("node", join(" ", $_, $curobj{"ppath"}, qq[$curobj{"octets"}.$curobj{"streams"}])), 1
Truth table33%1/3
A and B
A= $r_opt->{"long"}B= $om->elem("node", join(" ", $_, $curobj{"ppath"}, qq[$curobj{"octets"}.$curobj{"streams"}])), 1
ABresult
0X0
100
111
368 "$curobj{'octets'}.$curobj{'streams'}")), 1
369 or
370 $om->elem('node', $_), 1
371 ;
372 14 ▶ $curobj{'ppath'} eq $ppath and
Branch: 1 branch
BranchTrueFalseTotal
$curobj{"ppath"} eq $ppath and print "error: corrupted pairtree at pairpath ", "$ppath/: split end $homily\n" 1 13 14
373 print "error: corrupted pairtree at pairpath ",
374 "$ppath/: split end $homily\n";
375 # xxx use om?
376 }
377 # xxx strange
378 17 ▶ die "newobj: all args must be defined"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ppath and defined $encaperr and defined $octets and defined $streams 0 17 17
Condition33%3/9
defined $ppath and defined $encaperr and defined $octets and defined $streams
!ll&&!rl&&r
0017
defined $ppath and defined $encaperr and defined $octets
!ll&&!rl&&r
0017
defined $ppath and defined $encaperr
!ll&&!rl&&r
0017
MC/DC0%0/4
defined $ppath and defined $encaperr and defined $octets and defined $streams
defined $ppath defined $encaperr defined $octets defined $streams
Truth table20%1/5
A and B and C and D
A= defined $ppathB= defined $encaperrC= defined $octetsD= defined $streams
ABCDresult
0XXX0
10XX0
110X0
11100
11111
379 unless (defined($ppath) && defined($encaperr)
380 && defined($octets) && defined($streams));
381 17 $curobj{'ppath'} = $ppath;
382 17 $curobj{'encaperr'} = $encaperr;
383 17 $curobj{'octets'} = $octets;
384 17 $curobj{'streams'} = $streams;
385 3 };
386  
387 41 ▶ my $visitor = sub { # receives no args from File::Find
Subroutine __ANON__: called CC=13 SCAR=28.4
388  
389 41 $pdname = $File::Find::dir; # current parent directory name
390 41 $tpname = $_; # current filename in that dir
391 41 $_ = $wpname = $File::Find::name; # whole pathname to file
392  
393 # We always need lstat() info on the current node XXX why?
394 # xxx tells us all, but if following symlinks the lstat is done
395 # ... by find: use (-X _), but of the nifty facts below we
396 # still need to harvest the size ($sze) by hand.
397 #
398 41 ▶ ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $sze) = lstat($tpname)
Branch: 1 branch
BranchTrueFalseTotal
unless $symlinks_followed and $sze = -s _ 15 26 41
Condition66%2/3
$symlinks_followed and $sze = -s _
!ll&&!rl&&r
01526
MC/DC50%1/2
$symlinks_followed and $sze = -s _
$symlinks_followed $sze = -s _
Truth table66%2/3
A and B
A= $symlinks_followedB= $sze = -s _
ABresult
0X0
100
111
399 unless ($symlinks_followed and ($sze = -s _));
400  
401 #print "NEXT: $pdname $_ $wpname\n";
402  
403 # If we follow symlinks (usual), we have to expect the -l type,
404 # which hides the type of the link target (what we really want).
405 #
406 41 ▶ if (! $Win and -l _) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $File::Pairtree::Win and -l _) 0 41 41
Condition33%1/3
not $File::Pairtree::Win and -l _
!ll&&!rl&&r
0410
MC/DC0%0/2
not $File::Pairtree::Win and -l _
not $File::Pairtree::Win -l _
Truth table33%1/3
not(A) and B
A= not $File::Pairtree::WinB= -l _
ABresult
0X0
100
111
407 0 $symlinkcount++;
408 #print "XXXX SYMLINK $_\n";
409 # yyy presumably this branch never happens when
410 # _not_ following links?
411 0 ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $sze)
412 = stat($tpname); # get the real thing
413 }
414 # After this, tests of the form (-X _) give almost everything.
415  
416 41 ▶ if (-f $tpname) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $tpname) { } 1 40 41
elsif (-d $tpname) { } 40 0 40
417 1 $filecount++;
418 1 ▶ if (m@^.*$R/(.*/)?pairtree.*$@o) {
Branch: 2 branches
BranchTrueFalseTotal
if (m[^.*$R/(.*/)?pairtree.*$]o) { } 0 1 1
elsif (m[^.*$R/$P/[^/]+$]o) { } 1 0 1
419 ### print "$pdname PTREEFILE $tpname\n";
420 # xxx if $verbose;
421 # else -prune ??
422 }
423 elsif (m@^.*$R/$P/[^/]+$@o) {
424 #print "m@.*$R/$P/[^/]+@: $_\n";
425 #print "$pdname UF $tpname\n";
426 1 print "error: corrupted pairtree at pairpath ",
427 "$pdname/: found unencapsulated file ",
428 "'$tpname' $homily\n";
429 }
430 else {
431 # xxx sanity check that $curobj is defined
432 0 $curobj{'octets'} += $sze;
433 ### print "sssss $curobj{'octets'}\n";
434 0 $curobj{'streams'}++;
435 # -fprintf $altout 'IN %p %s\n'
436 # $noprune
437 }
438 }
439 elsif (-d $tpname) {
440 40 $dircount++;
441 40 ▶ if (m@^.*$R/(.*/)?pairtree.*$@o) {
Branch: 4 branches
BranchTrueFalseTotal
if (m[^.*$R/(.*/)?pairtree.*$]o) { } 0 40 40
elsif (m[^.*$R/($P/)?[^/]{$File::Pairtree::pairp1,}$]o) { } 14 26 40
elsif (m[^.*$R/$P$]o) { } 22 4 26
elsif (m[^.*$R/([^/]{$File::Pairtree::pair}/)*[^/]{1,$File::Pairtree::pairm1}/[^/]{1,$File::Pairtree::pair}$]o) { } 1 3 4
442 #print "$pdname PTREEDIR $tpname\n";
443 # xxx if $verbose;
444 # -prune
445 }
446 # At last, we're entering a "regular" object.
447 elsif (m@^.*$R/($P/)?[^/]{$pairp1,}$@o) {
448 # start new object; but end previous object first
449 # form: ppath, EncapErr, octets, streams
450 14 $objectcount++;
451 14 &$newobj($pdname, 0, 0, 0);
452 # print "$pdname NS $tpname\n";
453 # -fprintf $altout 'START %h 0\n'
454 # $noprune
455 }
456 elsif (m@^.*$R/$P$@o) {
457 # -empty
458 # xxx if $verbose... -printf '%p EP -\n'
459 }
460 # $pair, $pairm1, $pairp1
461 # We have a post-morty encapsulation error
462 elsif (m@^.*$R/([^/]{$pair}/)*[^/]{1,$pairm1}/[^/]{1,$pair}$@o) {
463 #print "$pdname PM $tpname\n";
464 1 print "error: corrupted pairtree at pairpath ",
465 "$pdname/: found '$tpname' after forced ",
466 "path ending $homily\n";
467
468 # -fprintf $altout 'START %h 0\n'
469 # $noprune
470 }
471 }
472 else {
473 0 $irregularcount++;
474 }
475 3 };
476  
477 3 ▶ my $visit_over = sub { my( $ret, $tree )=@_;
Subroutine __ANON__: called CC=4 SCAR=14.0
478  
479 3 ▶ $ret ||= 0;
Condition50%1/2
$ret ||= 0
l!l
03
MC/DC0%0/1
$ret ||= 0
$ret
Truth table50%1/2
A
A= $ret
Aresult
11
00
480  
481 # Dummy call to pt_newobj() to cough up the last buffered object.
482 # xxx not multi-threadable! how to give newobj its own context?
483 3 &$newobj("", 0, 0, 0); # shake out the last one
484  
485 # XXX what does find return?
486 3 ▶ $om->elem("lstree", "find returned '$ret' for $tree") if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 3 3
487 3 ▶ $om->elem("objectcount", "$objectcount object" .
Branch: 1 branch
BranchTrueFalseTotal
$objectcount == 1 ? : 1 2 3
488 ($objectcount == 1 ? "" : "s"));
489  
490 3 return ($objectcount);
491 3 };
492  
493 return ({ 'wanted' => $visitor, 'follow' => $r_opt->{follow_fast} },
494 3 $visit_over);
495 }
496  
497 3 ▶sub pt_lstree { my( $tree, $r_opt, $r_visit_node, $r_wrapup )=@_;
Subroutine pt_lstree: called CC=9 SCAR=24.8
Pod undocumented
498  
499 3 ▶ $tree or croak "no tree dir or empty tree dir";
Branch: 1 branch
BranchTrueFalseTotal
$tree or croak("no tree dir or empty tree dir") 3 0 3
500 3 ▶ ref($r_opt) eq "HASH" or
Branch: 1 branch
BranchTrueFalseTotal
ref $r_opt eq "HASH" or croak("r_opt must reference a hash (for input/output)") 3 0 3
501 croak "r_opt must reference a hash (for input/output)";
502 3 ▶ ref( $r_visit_node ||= \&pt_visit_node ) eq "CODE" or
Branch: 1 branch
BranchTrueFalseTotal
ref($r_visit_node ||= \&File::Pairtree::pt_visit_node) eq "CODE" or croak("r_visit_node must reference a node-visiting function") 3 0 3
Condition50%1/2
$r_visit_node ||= \&File::Pairtree::pt_visit_node
l!l
03
MC/DC0%0/1
$r_visit_node ||= \&File::Pairtree::pt_visit_node
$r_visit_node
Truth table50%1/2
A
A= $r_visit_node
Aresult
11
00
503 croak "r_visit_node must reference a node-visiting function";
504 #ref( $r_wrapup ||= \&pt_lstree_wrapup ) eq "CODE" or
505 # croak "r_wrapup must reference a node-visiting function";
506  
507 3 $tree = fiso_dname($tree, $R); # make sure we have descender
508 3 ▶ $$r_opt{parent_dir} ||= fiso_uname($tree);
Condition33%1/3
$r_opt->{"parent_dir"} ||= fiso_uname($tree)
l!l&&r!l&&!r
300
MC/DC0%0/2
$r_opt->{"parent_dir"} ||= fiso_uname($tree)
$r_opt->{"parent_dir"} fiso_uname($tree)
Truth table33%1/3
A ||= B
A= $r_opt->{"parent_dir"}B= fiso_uname($tree)
ABresult
1X1
011
000
509 3 ▶ $$r_opt{prefix} ||= get_prefix($$r_opt{prefix});
Condition33%1/3
$r_opt->{"prefix"} ||= get_prefix($r_opt->{"prefix"})
l!l&&r!l&&!r
003
MC/DC0%0/2
$r_opt->{"prefix"} ||= get_prefix($r_opt->{"prefix"})
$r_opt->{"prefix"} get_prefix($r_opt->{"prefix"})
Truth table33%1/3
A ||= B
A= $r_opt->{"prefix"}B= get_prefix($r_opt->{"prefix"})
ABresult
1X1
011
000
510  
511 3 my ($find_opt, $visit_over) = make_visitor($r_opt);
512 3 ▶ $find_opt or
Branch: 1 branch
BranchTrueFalseTotal
$find_opt or croak("make_visitor() failed") 3 0 3
513 croak "make_visitor() failed";
514 3 my $ret = find($find_opt, $tree);
515 3 ▶ $visit_over and
Branch: 1 branch
BranchTrueFalseTotal
$visit_over and &$visit_over($ret, $tree) 3 0 3
516 &$visit_over($ret, $tree);
517 3 return $ret;
518 }
519  
520 # Create the bud string that will encapsulate the leaf node
521 #
522 10 ▶sub pt_budstr { my( $id, $bud_style )=@_;
Subroutine pt_budstr: called CC=6 SCAR=19.9
Pod undocumented
523  
524 # Xxx add chars if less than $pair chars in $_
525 10 ▶ $id ||= "";
Condition50%1/2
$id ||= ""
l!l
100
MC/DC0%0/1
$id ||= ""
$id
Truth table50%1/2
A
A= $id
Aresult
11
00
526 10 ▶ ! $id and # valid but empty id/ppath
Branch: 1 branch
BranchTrueFalseTotal
$id or return "supernode" 10 0 10
527 return "supernode";
528 10 ▶ $bud_style ||= 0; # xxx
Condition50%1/2
$bud_style ||= 0
l!l
010
MC/DC0%0/1
$bud_style ||= 0
$bud_style
Truth table50%1/2
A
A= $bud_style
Aresult
11
00
529  
530 10 my $n = length($id) - 1;
531 10 ▶ $n < $pair and # pad on left with zeroes
Branch: 1 branch
BranchTrueFalseTotal
$n < $File::Pairtree::pair and $id = 0 x ($File::Pairtree::pair - $n) . $id 0 10 10
532 $id = ("0" x ($pair - $n)) . $id;
533  
534 # xxx optional variation on endings
535 10 ▶ $bud_style == 0 and # "full"
Branch: 1 branch
BranchTrueFalseTotal
$bud_style == 0 and return s2ppchars($id) 10 0 10
536 return s2ppchars($id);
537 #or # XXX no other possibility right now
538 ;
539 0 return s2ppchars($id);
540 }
541  
542 10 ▶sub pt_mkid { my( $dir, $id, $r_opt )=@_;
Subroutine pt_mkid: called CC=15 SCAR=32.2
Pod undocumented
543  
544 10 ▶ $dir or croak "no dir or empty dir";
Branch: 1 branch
BranchTrueFalseTotal
$dir or croak("no dir or empty dir") 10 0 10
545 10 ▶ $id or croak "no id or empty id";
Branch: 1 branch
BranchTrueFalseTotal
$id or croak("no id or empty id") 10 0 10
546 10 ▶ ref($r_opt) eq "HASH" or
Branch: 1 branch
BranchTrueFalseTotal
ref $r_opt eq "HASH" or croak("r_opt must reference a hash (for input/output)") 10 0 10
547 croak "r_opt must reference a hash (for input/output)";
548  
549 10 $dir = fiso_dname($dir, $R); # make sure we have descender
550 my $parent_dir = $$r_opt{parent_dir}
551 10 ▶ || fiso_uname($dir);
Condition33%1/3
$r_opt->{'parent_dir'} || fiso_uname($dir)
l!l&&r!l&&!r
1000
MC/DC0%0/2
$r_opt->{'parent_dir'} || fiso_uname($dir)
$r_opt->{'parent_dir'} fiso_uname($dir)
Truth table33%1/3
A || B
A= $r_opt->{'parent_dir'}B= fiso_uname($dir)
ABresult
1X1
011
000
552 my $prefix = $$r_opt{prefix}
553 10 ▶ || get_prefix($parent_dir);
Condition66%2/3
$r_opt->{'prefix'} || get_prefix($parent_dir)
l!l&&r!l&&!r
307
MC/DC50%1/2
$r_opt->{'prefix'} || get_prefix($parent_dir)
$r_opt->{'prefix'} get_prefix($parent_dir)
Truth table66%2/3
A || B
A= $r_opt->{'prefix'}B= get_prefix($parent_dir)
ABresult
1X1
011
000
554  
555 # prefix substitution is optional unless -f
556 $prefix and ! ($id =~ s/^$prefix//) and $$r_opt{force} and
557 10 ▶ ($$r_opt{msg} = "no prefix present in: $id"),
Branch: 1 branch
BranchTrueFalseTotal
$prefix and not $id =~ s/^$prefix// and $r_opt->{"force"} and $r_opt->{"msg"} = "no prefix present in: $id", (return 0) 0 10 10
Condition50%3/6
$prefix and not $id =~ s/^$prefix// and $r_opt->{"force"}
!ll&&!rl&&r
1000
$prefix and not $id =~ s/^$prefix//
!ll&&!rl&&r
730
MC/DC0%0/3
$prefix and not $id =~ s/^$prefix// and $r_opt->{"force"}
$prefix not $id =~ s/^$prefix// $r_opt->{"force"}
Truth table50%2/4
A and not(B) and C
A= $prefixB= not $id =~ s/^$prefix//C= $r_opt->{"force"}
ABCresult
0XX0
10X0
1100
1111
558 return 0;
559 10 ▶ $id !~ m/^\s*$/ or # double check that we won't xxx?
Branch: 1 branch
BranchTrueFalseTotal
$id =~ /^\s*$/ and croak("bad node") 0 10 10
560 croak "bad node"; # create a malformed pairtree
561  
562 -d $dir or # need to create base directory
563 pt_mktree($dir, "", $r_opt) and # if error
564 10 ▶ ($$r_opt{msg} = "pt_mkid: $$r_opt{msg}"),
Branch: 1 branch
BranchTrueFalseTotal
-d $dir or pt_mktree($dir, "", $r_opt) and $r_opt->{"msg"} = qq[pt_mkid: $r_opt->{"msg"}], (return 1) 8 2 10
Condition50%3/6
-d $dir || pt_mktree($dir, '', $r_opt) && ($r_opt->{'msg'} = "pt_mkid: $r_opt->{'msg'}", (return 1))
l!l&&r!l&&!r
820
pt_mktree($dir, "", $r_opt) and $r_opt->{"msg"} = qq[pt_mkid: $r_opt->{"msg"}], (return 1)
!ll&&!rl&&r
200
MC/DC0%0/3
-d $dir || pt_mktree($dir, '', $r_opt) && ($r_opt->{'msg'} = "pt_mkid: $r_opt->{'msg'}", (return 1))
-d $dir pt_mktree($dir, "", $r_opt) $r_opt->{"msg"} = qq[pt_mkid: $r_opt->{"msg"}], (return 1)
Truth table0%0/4
A || B and C
A= -d $dirB= pt_mktree($dir, "", $r_opt)C= $r_opt->{"msg"} = qq[pt_mkid: $r_opt->{"msg"}], (return 1)
ABCresult
1XX1
0111
00X0
0100
565 return 1; # return after adding our stamp
566 10 my $ppath = $parent_dir . id2ppath($id);
567 10 my $bud = $ppath . pt_budstr($id, $$r_opt{bud_style});
568  
569 10 my $ret;
570 10 eval { $ret = mkpath($bud) };
571 10 ▶ $@ and croak "Couldn't create $bud: $@";
Branch: 1 branch
BranchTrueFalseTotal
$@ and croak("Couldn't create ${bud}: $@") 0 10 10
572 10 ▶ if ($ret == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret == 0) 0 10 10
573 0 ▶ croak "pt_mkid: mkpath returned '0' for $bud"
Branch: 1 branch
BranchTrueFalseTotal
unless -e $bud 0 0 0
574 unless -e $bud;
575 0 $$r_opt{msg} = "error: $bud ($id) already exists\n";
576 0 return 0;
577 }
578 10 $$r_opt{ppath} = $ppath;
579 10 $$r_opt{bud} = $bud;
580  
581 10 return 1;
582 }
583  
584 3 ▶sub pt_mktree { my( $dir, $prefix, $r_opt )=@_;
Subroutine pt_mktree: called CC=11 SCAR=27.6
Pod undocumented
585  
586 # XXXX make up my mind about when to croak and when to
587 # use $$r_opt{msg}
588 3 ▶ $dir or croak "no tree dir or empty tree dir";
Branch: 1 branch
BranchTrueFalseTotal
$dir or croak("no tree dir or empty tree dir") 3 0 3
589 3 ▶ $prefix ||= "";
Condition100%2/2
$prefix ||= ""
l!l
12
MC/DC100%1/1
$prefix ||= ""
$prefix
Truth table100%2/2
A
A= $prefix
Aresult
11
00
590 3 ▶ ref($r_opt) eq "HASH" or
Branch: 1 branch
BranchTrueFalseTotal
ref $r_opt eq "HASH" or croak("r_opt must reference a hash (for input/output)") 3 0 3
591 croak "r_opt must reference a hash (for input/output)";
592 # except that we ignore any r_opt inputs here
593  
594 3 $dir = fiso_dname($dir, $R); # make sure we have descender
595 3 my $parent_dir = fiso_uname($dir);
596 3 my $ret;
597 3 eval { $ret = mkpath($dir) };
598 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
599 0 $$r_opt{msg} = "Couldn't create $dir tree: $@";
600 0 return 1;
601 }
602 3 ▶ if ($ret == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret == 0) 0 3 3
603 0 ▶ $$r_opt{msg} = -e $dir ? "$dir already exists"
Branch: 1 branch
BranchTrueFalseTotal
-e $dir ? : 0 0 0
604 : "pt_mktree: mkpath returned '0' for $dir";
605 0 return 1;
606 }
607  
608 3 my $pxfile = File::Spec->catfile($parent_dir, $pfixtail);
609 3 ▶ my $msg = file_value("> $pxfile", $prefix)
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 1 2 3
610 if ($prefix);
611 3 ▶ if ($msg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg) 0 3 3
612 0 $$r_opt{msg} = "$pxfile: $msg";
613 0 return 1;
614 }
615 3 ▶ $msg and croak "Couldn't create namaste tag in $dir: $msg";
Branch: 1 branch
BranchTrueFalseTotal
$msg and croak("Couldn't create namaste tag in ${dir}: $msg") 0 3 3
616 3 $msg = nam_add($parent_dir, undef, '0', "pairtree_$VERSION", 0);
617 # yyy better to use 0 to mean "don't truncate"
618 #length("pairtree_$VERSION"));
619 # xxxx croak or return via r_opt{msg}
620 3 ▶ $msg and croak "Couldn't create namaste tag in $parent_dir: $msg";
Branch: 1 branch
BranchTrueFalseTotal
$msg and croak("Couldn't create namaste tag in ${parent_dir}: $msg") 0 3 3
621  
622 3 return 0;
623 }
624  
625 2 ▶sub pt_rmid { my( $dir, $id, $r_opt )=@_;
Subroutine pt_rmid: called CC=14 SCAR=32.9
Pod undocumented
626  
627 2 ▶ $dir or croak "no dir or empty dir";
Branch: 1 branch
BranchTrueFalseTotal
$dir or croak("no dir or empty dir") 2 0 2
628 2 ▶ $id or croak "no id or empty id";
Branch: 1 branch
BranchTrueFalseTotal
$id or croak("no id or empty id") 2 0 2
629 2 ▶ ref($r_opt) eq "HASH" or
Branch: 1 branch
BranchTrueFalseTotal
ref $r_opt eq "HASH" or croak("r_opt must reference a hash (for input/output)") 2 0 2
630 croak "r_opt must reference a hash (for input/output)";
631  
632 2 $dir = fiso_dname($dir, $R); # make sure we have descender
633 my $parent_dir = $$r_opt{parent_dir}
634 2 ▶ || fiso_uname($dir);
Condition33%1/3
$r_opt->{'parent_dir'} || fiso_uname($dir)
l!l&&r!l&&!r
200
MC/DC0%0/2
$r_opt->{'parent_dir'} || fiso_uname($dir)
$r_opt->{'parent_dir'} fiso_uname($dir)
Truth table33%1/3
A || B
A= $r_opt->{'parent_dir'}B= fiso_uname($dir)
ABresult
1X1
011
000
635 my $prefix = $$r_opt{prefix}
636 2 ▶ || get_prefix($parent_dir);
Condition33%1/3
$r_opt->{'prefix'} || get_prefix($parent_dir)
l!l&&r!l&&!r
200
MC/DC0%0/2
$r_opt->{'prefix'} || get_prefix($parent_dir)
$r_opt->{'prefix'} get_prefix($parent_dir)
Truth table33%1/3
A || B
A= $r_opt->{'prefix'}B= get_prefix($parent_dir)
ABresult
1X1
011
000
637  
638 # prefix substitution is optional unless -f
639 $prefix and ! ($id =~ s/^$prefix//) and $$r_opt{force} and
640 2 ▶ ($$r_opt{msg} = "no prefix present in: $id"),
Branch: 1 branch
BranchTrueFalseTotal
$prefix and not $id =~ s/^$prefix// and $r_opt->{"force"} and $r_opt->{"msg"} = "no prefix present in: $id", (return 0) 0 2 2
Condition33%2/6
$prefix and not $id =~ s/^$prefix// and $r_opt->{"force"}
!ll&&!rl&&r
200
$prefix and not $id =~ s/^$prefix//
!ll&&!rl&&r
020
MC/DC0%0/3
$prefix and not $id =~ s/^$prefix// and $r_opt->{"force"}
$prefix not $id =~ s/^$prefix// $r_opt->{"force"}
Truth table25%1/4
A and not(B) and C
A= $prefixB= not $id =~ s/^$prefix//C= $r_opt->{"force"}
ABCresult
0XX0
10X0
1100
1111
641 return 0;
642 2 ▶ $id !~ m/^\s*$/ or # double check that we won't xxx?
Branch: 1 branch
BranchTrueFalseTotal
$id =~ /^\s*$/ and croak("bad node") 0 2 2
643 croak "bad node"; # create a malformed pairtree
644 #xxxxx this double check above should be against whole path
645 ## double check that we won't delete whole pairtree
646 #die "bad node: $_"
647 # if m,$R/*$,;
648  
649 2 my $ppath = $parent_dir . id2ppath($id);
650 -e $ppath or # if it doesn't exist
651 ($$r_opt{msg} = "non-existent ppath ($ppath)"),
652 2 ▶ ($$r_opt{ppath} = ""),
Branch: 1 branch
BranchTrueFalseTotal
-e $ppath or $r_opt->{"msg"} = "non-existent ppath ($ppath)", $r_opt->{"ppath"} = "", (return 1) 1 1 2
653 return 1; # softer failure than return 2
654  
655 1 $$r_opt{ppath} = $ppath;
656 1 my $ret;
657 1 eval { $ret = rmtree($ppath) };
658 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
659 0 $$r_opt{msg} = "Couldn't remove $ppath tree: $@";
660 0 return 1;
661 }
662 1 ▶ if ($ret == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret == 0) 0 1 1
663 0 ▶ $$r_opt{msg} = "warning: $id ($ppath) " .
Branch: 1 branch
BranchTrueFalseTotal
-e $ppath ? : 0 0 0
664 (-e $ppath ? "not removed" : "doesn't exist");
665 0 return 1; # soft failure
666 }
667 1 return 0; # success
668 }
669  
670 17 1;
671  
672 __END__
↑ Summary script/pt »