lib/Skilletor/Apply.pm

filter: Statementstmt 90.9% 311 / 342 Branchbran 69.5% 114 / 164 Conditioncond 55.4% 86 / 155 MC/DCmcdc 31.8% 29 / 91 Subroutinesub 97.1% 34 / 35 Podpod 100% 2 / 2 totaltotal 73.0% 576 / 789 CC 149 SCAR 37.3
CC
149
Cov
77%
_apply_plan
99.8
_remove_item_files
20.9
_inspect
14.8
CRAP 41.7
« /usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Class/XSAccessor.pm ↑ Summary /usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Sereal/Decoder.pm »
1 package Skilletor::Apply;
2 # ABSTRACT: Apply a build plan to disk – diff, atomic writes, conflicts, removal (spec §6.1–6.3)
3  
4 400 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 400 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 400 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 400 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 400 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 400 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 400 ▶use Skilletor::Entry qw( name_key );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 400 ▶use Skilletor::Error::Apply;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 400 ▶use Skilletor::FSUtil qw( atomic_write encode_text hash_bytes is_executable path_join path_resolve same_file );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 400 ▶use Skilletor::JSON qw( js_ordered );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 400 ▶use Skilletor::Lock qw( read_lock serialize_lock write_lock );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 400 our $VERSION = '0.008000';
18  
19 400 our @EXPORT_OK = qw( apply is_valid_item_name );
20  
21 400 my $NAME_RE = qr/\A[A-Za-z0-9._\-]+\z/;
22  
23 0 ▶sub is_valid_item_name { ( defined $_[0] && $_[0] =~ $NAME_RE ) ? 1 : 0 }
Subroutine is_valid_item_name: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && $_[0] =~ /$NAME_RE/ ? : 0 0 0
Condition0%0/3
defined $_[0] and $_[0] =~ /$NAME_RE/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0] and $_[0] =~ /$NAME_RE/
defined $_[0] $_[0] =~ /$NAME_RE/
Truth table0%0/3
A and B
A= defined $_[0]B= $_[0] =~ /$NAME_RE/
ABresult
0X0
100
111
24  
25 4004 ▶sub _uniq {
Subroutine _uniq: called CC=1 SCAR=0.0
26 4004 my %seen;
27 4004 return grep { !$seen{$_}++ } @_;
28 }
29  
30 565 ▶sub _dirname { my ( $p ) = @_; ( my $d = $p ) =~ s{/[^/]*\z}{}; return length $d ? $d : '/' }
Subroutine _dirname: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
length $d ? : 565 0 565
31  
32 4879 ▶sub apply {
Subroutine apply: called CC=3 SCAR=11.0
Pod documented
33 4879 my ( $plan, %opts ) = @_;
34 4879 my $lock_path = path_join( path_resolve( $opts{target_dir} ), 'skilletor.lock.json' );
35 4879 my $old_lock = read_lock($lock_path);
36 4878 my $landed = { order => [], by => {} };
37 4878 my $res;
38 4878 my $ok = eval { $res = _apply_plan( $plan, \%opts, $lock_path, $old_lock, $landed ); 1 };
39 4878 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 108 4770 4878
40 108 my $err = $@;
41 108 ▶ _write_salvage_lock( $lock_path, $old_lock, $landed ) if @{ $landed->{order} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$landed->{"order"};} 95 13 108
42 108 die $err;
43 }
44 4770 return $res;
45 }
46  
47 5165 ▶sub _entry {
Subroutine _entry: called CC=6 SCAR=17.9
48 5165 my ( $it, %fields ) = @_;
49 5165 my $e = js_ordered( source => $it->{source}, version => $it->{version}, files => $fields{files} );
50 5165 ▶ $e->{skipped} = $fields{skipped} if $fields{skipped};
Branch: 1 branch
BranchTrueFalseTotal
if $fields{"skipped"} 41 5124 5165
51 5165 ▶ $e->{block} = JSON::MaybeXS::true() if $fields{block};
Branch: 1 branch
BranchTrueFalseTotal
if $fields{"block"} 1154 4011 5165
52 5165 ▶ $e->{via} = [ @{ $it->{via} } ] if $it->{via} && @{ $it->{via} };
Branch: 1 branch
BranchTrueFalseTotal
if $it->{"via"} and @{$it->{"via"};} 240 4925 5165
Condition66%2/3
$it->{"via"} and @{$it->{"via"};}
!ll&&!rl&&r
49250240
MC/DC50%1/2
$it->{"via"} and @{$it->{"via"};}
$it->{"via"} @{$it->{"via"};}
Truth table66%2/3
A and B
A= $it->{"via"}B= @{$it->{"via"};}
ABresult
0X0
100
111
53 5165 ▶ $e->{partial} = JSON::MaybeXS::true() if $fields{partial};
Branch: 1 branch
BranchTrueFalseTotal
if $fields{"partial"} 95 5070 5165
54 5165 return $e;
55 }
56  
57 4608 ▶sub _files_of { my ( $e ) = @_; return ( $e && ref $e->{files} eq 'HASH' ) ? $e->{files} : {} }
Subroutine _files_of: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
$e && ref $e->{'files'} eq 'HASH' ? : 1839 2769 4608
Condition66%2/3
$e and ref $e->{"files"} eq "HASH"
!ll&&!rl&&r
276901839
MC/DC50%1/2
$e and ref $e->{"files"} eq "HASH"
$e ref $e->{"files"} eq "HASH"
Truth table66%2/3
A and B
A= $eB= ref $e->{"files"} eq "HASH"
ABresult
0X0
100
111
58  
59 4878 ▶sub _apply_plan {
Subroutine _apply_plan: called CC=67 SCAR=46.0
60 4878 my ( $plan, $opts, $lock_path, $old_lock, $landed ) = @_;
61 4878 my $target_dir = path_resolve( $opts->{target_dir} );
62 4878 my $new_lock = js_ordered();
63 4878 my $res = {
64 added => [], updated => [], removed => [], unchanged => [], skipped => [], conflicts => [], overwritten => [], written => [],
65 leftInPlace => [],
66 };
67 4878 my ( %dirs_touched, @touched_roots );
68 4878 ▶ my $root_for = sub { path_resolve( $opts->{root_of} ? $opts->{root_of}->( $_[0] ) : $target_dir ) };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'root_of'} ? : 4509 41 4550
69 4091 ▶ my $touched = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
70 4091 my ( $root ) = @_;
71 4091 ▶ unless ( $dirs_touched{$root} ) { $dirs_touched{$root} = { order => [], set => {} }; push @touched_roots, $root }
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirs_touched{$root}) 3332 759 4091
72 4091 return $dirs_touched{$root};
73 4878 };
74  
75 4878 my %planned = map { ( $_->{key} => 1 ) } @$plan;
76 4878 ▶ my %keep = map { ( $_ => 1 ) } @{ $opts->{keep} // [] };
Condition100%2/2
$opts->{"keep"} // []
l!l
483741
MC/DC100%1/1
$opts->{"keep"} // []
$opts->{"keep"}
Truth table100%2/2
A
A= $opts->{"keep"}
Aresult
11
00
77 # Entries leaving the lock that hold files: a planned item may find one of their files at its
78 # own path under a spelling equal ignoring case (k136).
79 my @leaving = grep {
80 4878 my $e = $old_lock->{$_};
81 2434 ▶ !$planned{$_} && !$keep{$_} && !$e->{block} && !$e->{skipped} && %{ _files_of($e) };
Condition83%10/12
!($planned{$_} || $keep{$_} || $e->{'block'} || $e->{'skipped'}) && %{_files_of($e);}
!ll&&!rl&&r
22590175
$planned{$_} || $keep{$_} || $e->{'block'} || $e->{'skipped'}
l!l&&r!l&&!r
22590175
$planned{$_} or $keep{$_} or $e->{"block"}
l!l&&r!l&&!r
222831175
$planned{$_} or $keep{$_}
l!l&&r!l&&!r
2058170206
MC/DC60%3/5
!($planned{$_} || $keep{$_} || $e->{'block'} || $e->{'skipped'}) && %{_files_of($e);}
$planned{$_} $keep{$_} $e->{"block"} $e->{'skipped'} %{_files_of($e);}
Truth table66%4/6
not(A or B or C || D) && E
A= $planned{$_}B= $keep{$_}C= $e->{"block"}D= $e->{'skipped'}E= %{_files_of($e);}
ABCDEresult
1XXXX0
01XXX0
001XX0
0001X0
000000
000011
82 } keys %$old_lock;
83  
84 4878 for my $it (@$plan) {
85 5240 ▶ Skilletor::Error::Apply->throw( 'invalid item name: '.$it->{name} ) unless $it->{name} =~ $NAME_RE;
Branch: 1 branch
BranchTrueFalseTotal
unless $it->{"name"} =~ /$NAME_RE/ 41 5199 5240
86 5199 ▶ if ( $it->{inBlock} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($it->{"inBlock"}) 1154 4045 5199
87 1154 _record_block_item( $it, $old_lock->{ $it->{key} }, $new_lock, $res );
88 1154 next;
89 }
90 4045 my $root = $root_for->( $it->{key} );
91 4045 ▶ if ( $it->{skipped} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($it->{"skipped"}) 41 4004 4045
92 # Owns no paths: delete only what the lock says was installed.
93 41 my @files = keys %{ _files_of( $old_lock->{ $it->{key} } ) };
94 41 _remove_item_files( $it->{key}, $root, \@files, $touched->($root), $res );
95 41 ▶ push @{ $res->{removed} }, $it->{key} if @files;
Branch: 1 branch
BranchTrueFalseTotal
if @files 41 0 41
96 41 push @{ $res->{skipped} }, $it->{key};
97 41 $new_lock->{ $it->{key} } = _entry( $it, files => js_ordered(), skipped => $it->{skipped} );
98 41 next;
99 }
100 # A previous skip entry owns nothing: the item counts as not yet installed.
101 4004 ▶ my $existing = ( $old_lock->{ $it->{key} } && !$old_lock->{ $it->{key} }{skipped} ) ? $old_lock->{ $it->{key} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$old_lock{$it->{'key'}} && !$$old_lock{$it->{'key'}}{'skipped'} ? : 1330 2674 4004
Condition66%2/3
$$old_lock{$it->{"key"}} and not $$old_lock{$it->{"key"}}{"skipped"}
!ll&&!rl&&r
267401330
MC/DC50%1/2
$$old_lock{$it->{"key"}} and not $$old_lock{$it->{"key"}}{"skipped"}
$$old_lock{$it->{"key"}} not $$old_lock{$it->{"key"}}{"skipped"}
Truth table66%2/3
A and not(B)
A= $$old_lock{$it->{"key"}}B= not $$old_lock{$it->{"key"}}{"skipped"}
ABresult
0X0
100
111
102 4004 my $ex_files = _files_of($existing);
103 4004 my @holders = ( $ex_files, map { _files_of( $old_lock->{$_} ) } grep { $root_for->($_) eq $root } @leaving );
104 4351 ▶ my $locked_hash = sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
105 4351 my ( $rel ) = @_;
106 4351 ▶ return $ex_files->{$rel} // _held( $root, $rel, \@holders );
Condition66%2/3
$ex_files->{$rel} // _held($root, $rel, \@holders)
l!l&&r!l&&!r
42480103
MC/DC50%1/2
$ex_files->{$rel} // _held($root, $rel, \@holders)
$ex_files->{$rel} _held($root, $rel, \@holders)
Truth table66%2/3
A // B
A= $ex_files->{$rel}B= _held($root, $rel, \@holders)
ABresult
1X1
011
000
107 4004 };
108 4004 ▶ my $owned = sub { defined $locked_hash->( $_[0] ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
109 4004 my $own = _own_path( $it->{key} );
110 4004 my %out = map { ( $_->[0] => $_->[1] ) } @{ $it->{output} };
111 4004 my @removals = grep { !exists $out{$_} } keys %$ex_files;
112  
113 # Every path of the item is checked before its first write (spec §6.3).
114 4004 my ( @found, @delete_first );
115 103 ▶ my $conflict = sub {
Subroutine __ANON__: called CC=6 SCAR=19.6
116 103 my ( $p, $not_file, $replace ) = @_;
117 103 ▶ return if grep { $_->{path} eq $p } @found;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->{"path"} eq $p;} @found 0 103 103
118 103 my $c = { key => $it->{key}, path => $p };
119 103 ▶ $c->{replace} = JSON::MaybeXS::true() if $replace;
Branch: 1 branch
BranchTrueFalseTotal
if $replace 0 103 103
120 103 ▶ $c->{notFile} = JSON::MaybeXS::true() if $not_file;
Branch: 1 branch
BranchTrueFalseTotal
if $not_file 0 103 103
121 103 push @found, $c;
122 103 ▶ push @delete_first, $p if $replace && !$not_file;
Branch: 1 branch
BranchTrueFalseTotal
if $replace and not $not_file 0 103 103
Condition33%1/3
$replace and not $not_file
!ll&&!rl&&r
10300
MC/DC0%0/2
$replace and not $not_file
$replace not $not_file
Truth table33%1/3
A and not(B)
A= $replaceB= not $not_file
ABresult
0X0
100
111
123 4004 };
124 4004 ▶ my %claims = map { ( $_ => 1 ) } @{ $it->{claims} // [] };
Condition100%2/2
$it->{"claims"} // []
l!l
7663238
MC/DC100%1/1
$it->{"claims"} // []
$it->{"claims"}
Truth table100%2/2
A
A= $it->{"claims"}
Aresult
11
00
125 4004 ▶ for my $rel ( _uniq( @{ $it->{claims} // [] }, ( map { $_->[0] } @{ $it->{output} } ), @removals ) ) {
Condition100%2/2
$it->{"claims"} // []
l!l
7663238
MC/DC100%1/1
$it->{"claims"} // []
$it->{"claims"}
Truth table100%2/2
A
A= $it->{"claims"}
Aresult
11
00
126 7461 my $at = _inspect( $root, $rel, $own );
127 7461 my $is_output = exists $out{$rel};
128 7461 ▶ if ( $at->{kind} eq 'blocked' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($at->{'kind'} eq 'blocked') { } 0 7461 7461
elsif (not $is_output || $claims{$rel}) { } 0 7461 7461
elsif ($at->{'kind'} eq 'other' and $is_output || !&$owned($rel)) { } 0 7461 7461
elsif ($at->{'kind'} eq 'file' || $at->{'kind'} eq 'link' and not &$owned($rel)) { } 103 12592 12695
129 # A link, or a file, where the item needs a directory: a conflict – unless it is one of
130 # the item's own files (the source turned it into a directory).
131 0 ▶ if ( $at->{link} || !$owned->( $at->{path} ) ) { $conflict->( $at->{path}, 0, 1 ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($at->{'link'} or not &$owned($at->{'path'})) { } 0 0 0
elsif (not grep({$_ eq $at->{'path'};} @delete_first)) { } 0 0 0
Condition0%0/3
$at->{"link"} or not &$owned($at->{"path"})
l!l&&r!l&&!r
000
MC/DC0%0/2
$at->{"link"} or not &$owned($at->{"path"})
$at->{"link"} not &$owned($at->{"path"})
Truth table0%0/3
A or not(B)
A= $at->{"link"}B= not &$owned($at->{"path"})
ABresult
1X1
011
000
132 0 elsif ( !grep { $_ eq $at->{path} } @delete_first ) { push @delete_first, $at->{path} }
133 }
134 ▶ elsif ( !$is_output && !$claims{$rel} ) {
Condition66%2/3
$is_output || $claims{$rel}
l!l&&r!l&&!r
66957660
MC/DC0%0/2
$is_output || $claims{$rel}
$is_output $claims{$rel}
Truth table66%2/3
A || B
A= $is_outputB= $claims{$rel}
ABresult
1X1
011
000
135 0 next; # only a removal: done after the writes
136 }
137 ▶ elsif ( $at->{kind} eq 'other' && ( $is_output || !$owned->($rel) ) ) {
Condition16%1/6
$at->{"kind"} eq "other" and $is_output || !&$owned($rel)
!ll&&!rl&&r
746100
$is_output or not &$owned($rel)
l!l&&r!l&&!r
000
MC/DC0%0/3
$at->{"kind"} eq "other" and $is_output || !&$owned($rel)
$at->{"kind"} eq "other" $is_output not &$owned($rel)
Truth table25%1/4
A and B or not(C)
A= $at->{"kind"} eq "other"B= $is_outputC= not &$owned($rel)
ABCresult
0XX0
1000
11X1
1011
138 0 $conflict->( $rel, 1, 0 );
139 }
140 ▶ elsif ( ( $at->{kind} eq 'file' || $at->{kind} eq 'link' ) && !$owned->($rel) ) {
Condition83%5/6
$at->{"kind"} eq "file" || $at->{"kind"} eq "link" and not &$owned($rel)
!ll&&!rl&&r
52342124103
$at->{"kind"} eq "file" or $at->{"kind"} eq "link"
l!l&&r!l&&!r
222705234
MC/DC66%2/3
$at->{"kind"} eq "file" || $at->{"kind"} eq "link" and not &$owned($rel)
$at->{"kind"} eq "file" $at->{"kind"} eq "link" not &$owned($rel)
Truth table60%3/5
A or B and not(C)
A= $at->{"kind"} eq "file"B= $at->{"kind"} eq "link"C= not &$owned($rel)
ABCresult
00X0
1X00
0100
1X11
0111
141 103 $conflict->( $rel, 0, !$is_output );
142 }
143 }
144 4004 ▶ my @blocking = grep { $_->{notFile} || !$opts->{force} } @found;
Condition33%1/3
$_->{'notFile'} || !$opts->{'force'}
l!l&&r!l&&!r
01030
MC/DC0%0/2
$_->{'notFile'} || !$opts->{'force'}
$_->{'notFile'} !$opts->{'force'}
Truth table33%1/3
A || not(B)
A= $_->{'notFile'}B= !$opts->{'force'}
ABresult
1X1
011
000
145 4004 ▶ if (@blocking) {
Branch: 1 branch
BranchTrueFalseTotal
if (@blocking) 62 3942 4004
146 62 push @{ $res->{conflicts} }, @blocking;
147 62 ▶ $new_lock->{ $it->{key} } = $old_lock->{ $it->{key} } if $old_lock->{ $it->{key} }; # left as it was
Branch: 1 branch
BranchTrueFalseTotal
if $$old_lock{$it->{"key"}} 0 62 62
148 62 push @{ $res->{unchanged} }, $it->{key};
149 62 next;
150 }
151 3942 _remove_file( _safe_join( $root, $_ ), $touched->($root) ) for @delete_first;
152  
153 3942 my $entry_files = js_ordered();
154 3942 my ( $wrote, $removed_file, $took_over ) = ( 0, 0, 0 );
155 4386 ▶ my $land = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
156 4386 my ( $rel, $hash ) = @_;
157 4386 push @{ $res->{written} }, { key => $it->{key}, path => $rel };
158 4386 ▶ unless ( $landed->{by}{ $it->{key} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($landed->{"by"}{$it->{"key"}}) 2592 1794 4386
159 2592 $landed->{by}{ $it->{key} } = { item => $it, files => js_ordered() };
160 2592 push @{ $landed->{order} }, $it->{key};
161 }
162 4386 $landed->{by}{ $it->{key} }{files}{$rel} = $hash;
163 3942 };
164  
165 3942 for my $pair ( @{ $it->{output} } ) {
166 6530 my ( $rel, $bytes ) = @$pair;
167 6530 my $abs = _safe_join( $root, $rel );
168 6530 my $desired = hash_bytes($bytes);
169 6530 ▶ my $executable = ( $it->{executable} // {} )->{$rel} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
+($it->{'executable'} // {})->{$rel} ? : 41 6489 6530
Condition100%2/2
$it->{"executable"} // {}
l!l
1236407
MC/DC100%1/1
$it->{"executable"} // {}
$it->{"executable"}
Truth table100%2/2
A
A= $it->{"executable"}
Aresult
11
00
170 6530 my $st = _lstat($abs);
171 6530 ▶ my $locked = $st ? $locked_hash->($rel) : $ex_files->{$rel};
Branch: 1 branch
BranchTrueFalseTotal
$st ? : 2124 4406 6530
172 6530 ▶ $took_over = 1 if defined $locked && !defined $ex_files->{$rel};
Branch: 1 branch
BranchTrueFalseTotal
if defined $locked and not defined $ex_files->{$rel} 0 6530 6530
Condition66%2/3
defined $locked and not defined $ex_files->{$rel}
!ll&&!rl&&r
440621240
MC/DC0%0/2
defined $locked and not defined $ex_files->{$rel}
defined $locked not defined $ex_files->{$rel}
Truth table66%2/3
A and not(B)
A= defined $lockedB= not defined $ex_files->{$rel}
ABresult
0X0
100
111
173  
174 6530 ▶ if ( $st && $st->{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st and $st->{'file'}) { } 2124 4406 6530
Condition66%2/3
$st and $st->{"file"}
!ll&&!rl&&r
440602124
MC/DC50%1/2
$st and $st->{"file"}
$st $st->{"file"}
Truth table66%2/3
A and B
A= $stB= $st->{"file"}
ABresult
0X0
100
111
175 2124 my $disk = hash_bytes( path( encode_text($abs) )->slurp_raw );
176 2124 ▶ if ( $disk eq $desired && is_executable( $st->{mode} ) == $executable ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($disk eq $desired and is_executable($st->{"mode"}) == $executable) 2077 47 2124
Condition66%2/3
$disk eq $desired and is_executable($st->{"mode"}) == $executable
!ll&&!rl&&r
4702077
MC/DC50%1/2
$disk eq $desired and is_executable($st->{"mode"}) == $executable
$disk eq $desired is_executable($st->{"mode"}) == $executable
Truth table66%2/3
A and B
A= $disk eq $desiredB= is_executable($st->{"mode"}) == $executable
ABresult
0X0
100
111
177 # Already correct; adopted into the lock (a stale hash updates silently).
178 2077 $entry_files->{$rel} = $desired;
179 2077 ▶ $land->( $rel, $desired ) unless defined $locked; # adopted (force)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $locked 0 2077 2077
180 2077 next;
181 }
182 47 atomic_write( encode_text($abs), $bytes, $executable );
183 47 ▶ if ( defined $locked && $disk ne $desired && $disk ne $locked ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $locked and $disk ne $desired and $disk ne $locked) 0 47 47
Condition33%2/6
defined $locked and $disk ne $desired and $disk ne $locked
!ll&&!rl&&r
0470
defined $locked and $disk ne $desired
!ll&&!rl&&r
0047
MC/DC0%0/3
defined $locked and $disk ne $desired and $disk ne $locked
defined $locked $disk ne $desired $disk ne $locked
Truth table25%1/4
A and B and C
A= defined $lockedB= $disk ne $desiredC= $disk ne $locked
ABCresult
0XX0
10X0
1100
1111
184 0 push @{ $res->{overwritten} }, { key => $it->{key}, path => $rel }; # local drift; the bit alone is none
185 }
186 }
187 else {
188 # Missing, or a link the lock owns (or force adopts): the rename replaces the link itself.
189 4406 atomic_write( encode_text($abs), $bytes, $executable );
190 0 ▶ push @{ $res->{overwritten} }, { key => $it->{key}, path => $rel } if $st && defined $locked;
Branch: 1 branch
BranchTrueFalseTotal
if $st and defined $locked 0 4339 4339
Condition33%1/3
$st and defined $locked
!ll&&!rl&&r
433900
MC/DC0%0/2
$st and defined $locked
$st defined $locked
Truth table33%1/3
A and B
A= $stB= defined $locked
ABresult
0X0
100
111
191 }
192 4386 $wrote = 1;
193 4386 $entry_files->{$rel} = $desired;
194 4386 $land->( $rel, $desired );
195 }
196  
197 # Files the item no longer contains but the lock still tracks – save one that is a file of
198 # its output under another spelling (k136).
199 3875 my $outputs = [ { map { ( $_->[0] => '' ) } @{ $it->{output} } } ];
200 0 my @gone = grep { !defined _held( $root, $_, $outputs ) } @removals;
201 3875 ▶ $removed_file = 1 if _remove_item_files( $it->{key}, $root, \@gone, $touched->($root), $res );
Branch: 1 branch
BranchTrueFalseTotal
if _remove_item_files($it->{"key"}, $root, \@gone, &$touched($root), $res) 0 3875 3875
202 3875 ▶ $took_over = 1 if @gone < @removals;
Branch: 1 branch
BranchTrueFalseTotal
if @gone < @removals 0 3875 3875
203  
204 3875 ▶ $new_lock->{ $it->{key} } = _entry( $it, files => $entry_files ) if %$entry_files;
Branch: 1 branch
BranchTrueFalseTotal
if %$entry_files 3875 0 3875
205  
206 3875 ▶ if ( !$existing ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $existing) { } 2545 1330 3875
elsif ($wrote or $removed_file or $took_over or $existing->{'partial'}) { } 101 1229 1330
207 2545 ▶ if ( $wrote || $took_over ) { push @{ $res->{added} }, $it->{key} }
Branch: 1 branch
BranchTrueFalseTotal
if ($wrote or $took_over) { } 2545 0 2545
Condition33%1/3
$wrote or $took_over
l!l&&r!l&&!r
254500
MC/DC0%0/2
$wrote or $took_over
$wrote $took_over
Truth table33%1/3
A or B
A= $wroteB= $took_over
ABresult
1X1
011
000
208 0 else { push @{ $res->{unchanged} }, $it->{key} } # fully conflicted
209 }
210 ▶ elsif ( $wrote || $removed_file || $took_over || $existing->{partial} ) {
Condition77%7/9
$wrote or $removed_file or $took_over or $existing->{"partial"}
l!l&&r!l&&!r
47541229
$wrote or $removed_file or $took_over
l!l&&r!l&&!r
4701283
$wrote or $removed_file
l!l&&r!l&&!r
4701283
MC/DC50%2/4
$wrote or $removed_file or $took_over or $existing->{"partial"}
$wrote $removed_file $took_over $existing->{"partial"}
Truth table60%3/5
A or B or C or D
A= $wroteB= $removed_fileC= $took_overD= $existing->{"partial"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
211 101 push @{ $res->{updated} }, $it->{key}; # a partial entry: the run that left it never reported it
212 }
213 else {
214 1229 push @{ $res->{unchanged} }, $it->{key};
215 }
216 }
217  
218 # Items no longer declared: their locked files go (unless kept) – but none the new lock holds
219 # under another spelling (k136).
220 175 ▶ my $kept = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
221 175 my ( $root ) = @_;
222 175 ▶ return [ map { _files_of( $new_lock->{$_} ) } grep { !$new_lock->{$_}{block} && $root_for->($_) eq $root } keys %$new_lock ];
Condition100%3/3
!$new_lock->{$_}{'block'} && &$root_for($_) eq $root
!ll&&!rl&&r
1210659
MC/DC100%2/2
!$new_lock->{$_}{'block'} && &$root_for($_) eq $root
!$new_lock->{$_}{'block'} &$root_for($_) eq $root
Truth table100%3/3
not(A) && B
A= !$new_lock->{$_}{'block'}B= &$root_for($_) eq $root
ABresult
0X0
100
111
223 4770 };
224 4770 for my $key ( keys %$old_lock ) {
225 2421 ▶ next if $planned{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $planned{$key} 2045 376 2421
226 376 ▶ if ( $keep{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keep{$key}) 170 206 376
227 170 $new_lock->{$key} = $old_lock->{$key}; # preserved untouched
228 170 next;
229 }
230 206 ▶ unless ( $old_lock->{$key}{block} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($old_lock->{$key}{"block"}) 175 31 206
231 175 my $root = $root_for->($key);
232 175 my $holders = $kept->($root);
233 175 my @files = grep { !defined _held( $root, $_, $holders ) } keys %{ _files_of( $old_lock->{$key} ) };
234 175 _remove_item_files( $key, $root, \@files, $touched->($root), $res );
235 }
236 206 ▶ push @{ $res->{removed} }, $key unless $old_lock->{$key}{skipped}; # a skip entry had nothing installed
Branch: 1 branch
BranchTrueFalseTotal
unless $old_lock->{$key}{"skipped"} 206 0 206
237 }
238  
239 4770 _prune_empty_dirs( $dirs_touched{$_}{order}, $_ ) for @touched_roots;
240  
241 # The lock is rewritten only when it changed (no-op runs stay write-free); without entries it
242 # goes, a `{}` an earlier version left included.
243 4770 ▶ my $empty_left = !%$new_lock && -e encode_text($lock_path);
Condition100%3/3
!%$new_lock && -e encode_text($lock_path)
!ll&&!rl&&r
3657107043
MC/DC100%2/2
!%$new_lock && -e encode_text($lock_path)
!%$new_lock -e encode_text($lock_path)
Truth table100%3/3
not(A) && B
A= !%$new_lockB= -e encode_text($lock_path)
ABresult
0X0
100
111
244 4770 ▶ write_lock( $lock_path, $new_lock ) if $empty_left || serialize_lock($new_lock) ne serialize_lock($old_lock);
Branch: 1 branch
BranchTrueFalseTotal
if $empty_left or serialize_lock($new_lock) ne serialize_lock($old_lock) 2363 2407 4770
Condition100%3/3
$empty_left or serialize_lock($new_lock) ne serialize_lock($old_lock)
l!l&&r!l&&!r
4323202407
MC/DC100%2/2
$empty_left or serialize_lock($new_lock) ne serialize_lock($old_lock)
$empty_left serialize_lock($new_lock) ne serialize_lock($old_lock)
Truth table100%3/3
A or B
A= $empty_leftB= serialize_lock($new_lock) ne serialize_lock($old_lock)
ABresult
1X1
011
000
245 4770 return $res;
246 }
247  
248 # The lock after a run that threw (spec §6.2, k71): the old lock plus every file the run wrote
249 # or adopted, under its item marked partial. Best effort.
250 95 ▶sub _write_salvage_lock {
Subroutine _write_salvage_lock: called CC=5 SCAR=16.5
251 95 my ( $lock_path, $old_lock, $landed ) = @_;
252 0 my $lock = js_ordered( map { ( $_ => $old_lock->{$_} ) } keys %$old_lock );
253 95 for my $key ( @{ $landed->{order} } ) {
254 95 my ( $item, $files ) = @{ $landed->{by}{$key} }{qw( item files )};
255 95 ▶ my $prev = ( $old_lock->{$key} && !$old_lock->{$key}{skipped} ) ? $old_lock->{$key} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$old_lock->{$key} && !$old_lock->{$key}{'skipped'} ? : 0 95 95
Condition33%1/3
$old_lock->{$key} and not $old_lock->{$key}{"skipped"}
!ll&&!rl&&r
9500
MC/DC0%0/2
$old_lock->{$key} and not $old_lock->{$key}{"skipped"}
$old_lock->{$key} not $old_lock->{$key}{"skipped"}
Truth table33%1/3
A and not(B)
A= $old_lock->{$key}B= not $old_lock->{$key}{"skipped"}
ABresult
0X0
100
111
256 95 my $merged = js_ordered( %{ _files_of($prev) } );
257 95 $merged->{$_} = $files->{$_} for keys %$files;
258 95 $lock->{$key} = _entry( $item, files => $merged, partial => 1 );
259 }
260 95 eval { write_lock( $lock_path, $lock ); 1 };
261 }
262  
263 # Lock and report a block section by its hash; no disk access.
264 1154 ▶sub _record_block_item {
Subroutine _record_block_item: called CC=7 SCAR=23.0
265 1154 my ( $it, $prev, $new_lock, $res ) = @_;
266 1154 ▶ my $had = ( $prev && !$prev->{skipped} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$prev && !$prev->{'skipped'} ? : 687 467 1154
Condition66%2/3
$prev and not $prev->{"skipped"}
!ll&&!rl&&r
4670687
MC/DC50%1/2
$prev and not $prev->{"skipped"}
$prev not $prev->{"skipped"}
Truth table66%2/3
A and not(B)
A= $prevB= not $prev->{"skipped"}
ABresult
0X0
100
111
267 1154 ▶ if ( $it->{skipped} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($it->{"skipped"}) 0 1154 1154
268 0 ▶ push @{ $res->{removed} }, $it->{key} if $had;
Branch: 1 branch
BranchTrueFalseTotal
if $had 0 0 0
269 0 push @{ $res->{skipped} }, $it->{key};
270 0 $new_lock->{ $it->{key} } = _entry( $it, files => js_ordered(), skipped => $it->{skipped}, block => 1 );
271 0 return;
272 }
273 1154 my $files = js_ordered( map { ( $_->[0] => hash_bytes( $_->[1] ) ) } @{ $it->{output} } );
274 1154 $new_lock->{ $it->{key} } = _entry( $it, files => $files, block => 1 );
275 1154 ▶ if ( !$had ) { push @{ $res->{added} }, $it->{key} }
Branch: 2 branches
BranchTrueFalseTotal
if (not $had) { } 467 687 1154
elsif (Skilletor::JSON::js_stringify($prev->{'files'}) ne Skilletor::JSON::js_stringify($files)) { } 0 687 687
276 0 elsif ( Skilletor::JSON::js_stringify( $prev->{files} ) ne Skilletor::JSON::js_stringify($files) ) { push @{ $res->{updated} }, $it->{key} }
277 687 else { push @{ $res->{unchanged} }, $it->{key} }
278 }
279  
280 # The hash `holders` give the file at $rel under another spelling of it (k136): a path equal
281 # ignoring case that is the same file on disk.
282 355 ▶sub _held {
Subroutine _held: called CC=6 SCAR=21.8
283 355 my ( $root, $rel, $holders ) = @_;
284 355 my $k = name_key($rel);
285 355 for my $files (@$holders) {
286 166 for my $other ( keys %$files ) {
287 157 ▶ next if $other eq $rel || name_key($other) ne $k;
Branch: 1 branch
BranchTrueFalseTotal
if $other eq $rel or name_key($other) ne $k 157 0 157
Condition33%1/3
$other eq $rel or name_key($other) ne $k
l!l&&r!l&&!r
01570
MC/DC0%0/2
$other eq $rel or name_key($other) ne $k
$other eq $rel name_key($other) ne $k
Truth table33%1/3
A or B
A= $other eq $relB= name_key($other) ne $k
ABresult
1X1
011
000
288 0 ▶ return $files->{$other} if same_file( _safe_join( $root, $other ), _safe_join( $root, $rel ) );
Branch: 1 branch
BranchTrueFalseTotal
if same_file(_safe_join($root, $other), _safe_join($root, $rel)) 0 0 0
289 }
290 }
291 355 return undef;
292 }
293  
294 14577 ▶sub _safe_join {
Subroutine _safe_join: called CC=3 SCAR=12.0
295 14577 my ( $root, $rel ) = @_;
296 14577 my $abs = path_resolve( path_join( $root, $rel ) );
297 14577 ▶ Skilletor::Error::Apply->throw( 'path escapes target: '.$rel ) if $abs ne $root && index( $abs, $root.'/' ) != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $abs ne $root and index($abs, $root . '/') != 0 0 14577 14577
Condition33%1/3
$abs ne $root and index($abs, $root . '/') != 0
!ll&&!rl&&r
0145770
MC/DC0%0/2
$abs ne $root and index($abs, $root . '/') != 0
$abs ne $root index($abs, $root . '/') != 0
Truth table33%1/3
A and B
A= $abs ne $rootB= index($abs, $root . '/') != 0
ABresult
0X0
100
111
298 14577 return $abs;
299 }
300  
301 # The item's own path under its root: the lock key without a `<prefix>:`.
302 8095 ▶sub _own_path {
Subroutine _own_path: called CC=4 SCAR=14.6
303 8095 my ( $key ) = @_;
304 8095 my ( $colon, $slash ) = ( index( $key, ':' ), index( $key, '/' ) );
305 8095 ▶ return ( $colon != -1 && ( $slash == -1 || $colon < $slash ) ) ? substr( $key, $colon + 1 ) : $key;
Branch: 1 branch
BranchTrueFalseTotal
$colon != -1 && ($slash == -1 || $colon < $slash) ? : 2350 5745 8095
Condition50%3/6
$colon != -1 and $slash == -1 || $colon < $slash
!ll&&!rl&&r
574502350
$slash == -1 or $colon < $slash
l!l&&r!l&&!r
023500
MC/DC33%1/3
$colon != -1 and $slash == -1 || $colon < $slash
$colon != -1 $slash == -1 $colon < $slash
Truth table50%2/4
A and B or C
A= $colon != -1B= $slash == -1C= $colon < $slash
ABCresult
0XX0
1000
11X1
1011
306 }
307  
308 # lstat answering undef for a missing path (also below a non-directory).
309 17279 ▶sub _lstat {
Subroutine _lstat: called CC=7 SCAR=20.1
310 17279 my ( $abs ) = @_;
311 17279 my @st = lstat encode_text($abs);
312 17279 ▶ unless (@st) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@st) 9640 7639 17279
313 9640 ▶ return undef if $!{ENOENT} || $!{ENOTDIR};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"ENOENT"} or $!{"ENOTDIR"} 9640 0 9640
Condition66%2/3
$!{"ENOENT"} or $!{"ENOTDIR"}
l!l&&r!l&&!r
9562780
MC/DC0%0/2
$!{"ENOENT"} or $!{"ENOTDIR"}
$!{"ENOENT"} $!{"ENOTDIR"}
Truth table66%2/3
A or B
A= $!{"ENOENT"}B= $!{"ENOTDIR"}
ABresult
1X1
011
000
314 0 die 'lstat '.$abs.': '.$!."\n";
315 }
316 7639 ▶ return { link => ( -l _ ? 1 : 0 ), dir => ( -d _ ? 1 : 0 ), file => ( -f _ ? 1 : 0 ), mode => $st[2] };
Branch: 3 branches
BranchTrueFalseTotal
-l _ ? : 0 7639 7639
-d _ ? : 2702 4937 7639
-f _ ? : 4937 2702 7639
317 }
318  
319 # What is at $rel (spec §6.3), looking at every component from the item's own path down
320 # without following links.
321 7754 ▶sub _inspect {
Subroutine _inspect: called CC=12 SCAR=27.0
322 7754 my ( $root, $rel, $own ) = @_;
323 7754 my $abs = _safe_join( $root, $rel );
324 7754 ▶ my @parts = split m{/}, ( $abs eq $root ? '' : substr( $abs, length($root) + 1 ) ), -1;
Branch: 1 branch
BranchTrueFalseTotal
$abs eq $root ? : 0 7754 7754
325 7754 ▶ @parts = ('') unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 0 7754 7754
326 7754 my @own_parts = split m{/}, $own, -1;
327 7754 ▶ my $under = @parts > @own_parts && !grep { $own_parts[$_] ne $parts[$_] } 0 .. $#own_parts;
Condition66%2/3
@parts > @own_parts && !grep({$own_parts[$_] ne $parts[$_];} 0 .. $#own_parts)
!ll&&!rl&&r
163006124
MC/DC50%1/2
@parts > @own_parts && !grep({$own_parts[$_] ne $parts[$_];} 0 .. $#own_parts)
@parts > @own_parts !grep({$own_parts[$_] ne $parts[$_];} 0 .. $#own_parts)
Truth table66%2/3
A && not(B)
A= @parts > @own_partsB= !grep({$own_parts[$_] ne $parts[$_];} 0 .. $#own_parts)
ABresult
0X0
100
111
328 7754 ▶ my $first = $under ? $#own_parts : $#parts;
Branch: 1 branch
BranchTrueFalseTotal
$under ? : 6124 1630 7754
329 7754 for my $i ( $first .. $#parts ) {
330 10146 ▶ my $st = _lstat( path_join( $root, @parts[ 0 .. $i ] ) ) or return { kind => 'absent' };
Branch: 1 branch
BranchTrueFalseTotal
my $st = _lstat(path_join($root, @parts[0 .. $i])) or return {"kind", "absent"} 4912 5234 10146
331 4912 ▶ if ( $i < $#parts ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i < $#parts) { } 2392 2520 4912
elsif ($st->{'link'}) { } 0 2520 2520
332 2392 ▶ return { kind => 'blocked', path => join( '/', @parts[ 0 .. $i ] ), link => $st->{link} } unless $st->{dir} && !$st->{link};
Branch: 1 branch
BranchTrueFalseTotal
unless $st->{"dir"} and not $st->{"link"} 0 2392 2392
Condition33%1/3
$st->{"dir"} and not $st->{"link"}
!ll&&!rl&&r
002392
MC/DC0%0/2
$st->{"dir"} and not $st->{"link"}
$st->{"dir"} not $st->{"link"}
Truth table33%1/3
A and not(B)
A= $st->{"dir"}B= not $st->{"link"}
ABresult
0X0
100
111
333 }
334 elsif ( $st->{link} ) {
335 0 return { kind => 'link' };
336 }
337 else {
338 2520 ▶ return { kind => $st->{file} ? 'file' : 'other' };
Branch: 1 branch
BranchTrueFalseTotal
$st->{'file'} ? : 2520 0 2520
339 }
340 }
341 0 return { kind => 'absent' };
342 }
343  
344 # Delete an item's lock-owned files – a link there itself, never through a link at or below the
345 # item's path (reported in leftInPlace). True when anything was deleted.
346 4091 ▶sub _remove_item_files {
Subroutine _remove_item_files: called CC=8 SCAR=30.4
347 4091 my ( $key, $root, $files, $dirs, $res ) = @_;
348 4091 my $own = _own_path($key);
349 4091 my $removed = 0;
350 4091 for my $rel (@$files) {
351 293 my $at = _inspect( $root, $rel, $own );
352 293 ▶ if ( $at->{kind} eq 'blocked' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($at->{'kind'} eq 'blocked') { } 0 293 293
elsif ($at->{'kind'} eq 'file' or $at->{'kind'} eq 'link') { } 293 0 293
353 0 ▶ if ( $at->{link} && !grep { $_->{key} eq $key && $_->{path} eq $at->{path} } @{ $res->{leftInPlace} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at->{"link"} and not grep({$_->{"key"} eq $key and $_->{"path"} eq $at->{"path"};} @{$$res{"leftInPlace"};})) 0 0 0
Condition0%0/6
$at->{"link"} and not grep({$_->{"key"} eq $key and $_->{"path"} eq $at->{"path"};} @{$$res{"leftInPlace"};})
!ll&&!rl&&r
000
$_->{'key'} eq $key && $_->{'path'} eq $at->{'path'}
!ll&&!rl&&r
000
MC/DC0%0/2
$at->{"link"} and not grep({$_->{"key"} eq $key and $_->{"path"} eq $at->{"path"};} @{$$res{"leftInPlace"};})
$at->{"link"} not grep({$_->{"key"} eq $key and $_->{"path"} eq $at->{"path"};} @{$$res{"leftInPlace"};})
MC/DC0%0/2
$_->{'key'} eq $key && $_->{'path'} eq $at->{'path'}
$_->{'key'} eq $key $_->{'path'} eq $at->{'path'}
Truth table0%0/3
A and not(B)
A= $at->{"link"}B= not grep({$_->{"key"} eq $key and $_->{"path"} eq $at->{"path"};} @{$$res{"leftInPlace"};})
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= $_->{'key'} eq $keyB= $_->{'path'} eq $at->{'path'}
ABresult
0X0
100
111
354 0 push @{ $res->{leftInPlace} }, { key => $key, path => $at->{path} };
355 }
356 }
357 ▶ elsif ( $at->{kind} eq 'file' || $at->{kind} eq 'link' ) {
Condition33%1/3
$at->{"kind"} eq "file" or $at->{"kind"} eq "link"
l!l&&r!l&&!r
29300
MC/DC0%0/2
$at->{"kind"} eq "file" or $at->{"kind"} eq "link"
$at->{"kind"} eq "file" $at->{"kind"} eq "link"
Truth table33%1/3
A or B
A= $at->{"kind"} eq "file"B= $at->{"kind"} eq "link"
ABresult
1X1
011
000
358 293 _remove_file( _safe_join( $root, $rel ), $dirs );
359 293 $removed = 1;
360 }
361 }
362 4091 return $removed;
363 }
364  
365 # Delete a file or link (never a directory, never through the final link).
366 293 ▶sub _remove_file {
Subroutine _remove_file: called CC=7 SCAR=22.4
367 293 my ( $abs, $dirs ) = @_;
368 293 my $st = _lstat($abs);
369 293 ▶ return unless $st && ( $st->{link} || !$st->{dir} );
Branch: 1 branch
BranchTrueFalseTotal
unless $st and $st->{"link"} || !$st->{"dir"} 0 293 293
Condition33%2/6
$st and $st->{"link"} || !$st->{"dir"}
!ll&&!rl&&r
00293
$st->{"link"} or not $st->{"dir"}
l!l&&r!l&&!r
02930
MC/DC0%0/3
$st and $st->{"link"} || !$st->{"dir"}
$st $st->{"link"} not $st->{"dir"}
Truth table25%1/4
A and B or not(C)
A= $stB= $st->{"link"}C= not $st->{"dir"}
ABCresult
0XX0
1000
11X1
1011
370 293 ▶ unlink encode_text($abs) or $!{ENOENT} or die 'unlink '.$abs.': '.$!."\n";
Branch: 1 branch
BranchTrueFalseTotal
unlink encode_text($abs) or $!{"ENOENT"} or die 'unlink ' . $abs . ': ' . $! . "\n" 293 0 293
Condition33%1/3
unlink encode_text($abs) or $!{"ENOENT"}
l!l&&r!l&&!r
29300
MC/DC0%0/2
unlink encode_text($abs) or $!{"ENOENT"}
unlink encode_text($abs) $!{"ENOENT"}
Truth table33%1/3
A or B
A= unlink encode_text($abs)B= $!{"ENOENT"}
ABresult
1X1
011
000
371 293 my $d = _dirname($abs);
372 293 ▶ push @{ $dirs->{order} }, $d unless $dirs->{set}{$d}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $dirs->{"set"}{$d}++ 212 81 293
373 }
374  
375 # Remove now-empty directories deleted from, walking up to (not including) the root; a link on
376 # the way ends the walk.
377 3224 ▶sub _prune_empty_dirs {
Subroutine _prune_empty_dirs: called CC=11 SCAR=25.1
378 3224 my ( $dirs, $root ) = @_;
379 3224 for my $start ( sort { length($b) <=> length($a) } @$dirs ) {
380 212 my $dir = $start;
381 212 ▶ while ( $dir ne $root && index( $dir, $root.'/' ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir ne $root and index($dir, $root . '/') == 0) 310 174 484
Condition66%2/3
$dir ne $root and index($dir, $root . '/') == 0
!ll&&!rl&&r
1740310
MC/DC50%1/2
$dir ne $root and index($dir, $root . '/') == 0
$dir ne $root index($dir, $root . '/') == 0
Truth table66%2/3
A and B
A= $dir ne $rootB= index($dir, $root . '/') == 0
ABresult
0X0
100
111
382 310 my $st = _lstat($dir);
383 310 ▶ last unless $st && $st->{dir} && !$st->{link};
Branch: 1 branch
BranchTrueFalseTotal
unless $st and $st->{"dir"} and not $st->{"link"} 0 310 310
Condition33%2/6
$st and $st->{"dir"} and not $st->{"link"}
!ll&&!rl&&r
00310
$st and $st->{"dir"}
!ll&&!rl&&r
00310
MC/DC0%0/3
$st and $st->{"dir"} and not $st->{"link"}
$st $st->{"dir"} not $st->{"link"}
Truth table25%1/4
A and B and not(C)
A= $stB= $st->{"dir"}C= not $st->{"link"}
ABCresult
0XX0
10X0
1100
1111
384 310 ▶ opendir( my $dh, encode_text($dir) ) or last;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, encode_text($dir) or last 310 0 310
385 310 ▶ my $empty = !grep { $_ ne '.' && $_ ne '..' } readdir $dh;
Condition100%3/3
$_ ne '.' && $_ ne '..'
!ll&&!rl&&r
31031038
MC/DC100%2/2
$_ ne '.' && $_ ne '..'
$_ ne '.' $_ ne '..'
Truth table100%3/3
A && B
A= $_ ne '.'B= $_ ne '..'
ABresult
0X0
100
111
386 310 closedir $dh;
387 310 ▶ last unless $empty;
Branch: 1 branch
BranchTrueFalseTotal
unless $empty 38 272 310
388 272 ▶ rmdir encode_text($dir) or die 'rmdir '.$dir.': '.$!."\n";
Branch: 1 branch
BranchTrueFalseTotal
rmdir encode_text($dir) or die 'rmdir ' . $dir . ': ' . $! . "\n" 272 0 272
389 272 $dir = _dirname($dir);
390 }
391 }
392 }
393  
394 400 1;
395  
396 __END__
« /usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Class/XSAccessor.pm ↑ Summary /usr/local/lib/perl5/site_perl/5.44.0/x86_64-linux/Sereal/Decoder.pm »