Skilletor/Apply.pm

filter: Statementstmt 64.3% 220 / 342 Branchbran 43.2% 71 / 164 Conditioncond 30.3% 47 / 155 MC/DCmcdc 9.8% 9 / 91 Subroutinesub 80.0% 28 / 35 Podpod 100% 2 / 2 totaltotal 47.7% 377 / 789 CC 149 SCAR 52.2
CC
149
Cov
51%
_apply_plan
454.1
_prune_empty_dirs
112.9
_record_block_item
56.0
CRAP 184.5
« Skilletor/ClaudeSettings.pm ↑ Summary Skilletor/Resolver.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 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 31 ▶use Errno ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 31 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 31 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 31 ▶use Skilletor::Entry qw( name_key );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 31 ▶use Skilletor::Error::Apply;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 31 ▶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 31 ▶use Skilletor::JSON qw( js_ordered );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 31 ▶use Skilletor::Lock qw( read_lock serialize_lock write_lock );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 31 our $VERSION = '0.001';
18  
19 31 our @EXPORT_OK = qw( apply is_valid_item_name );
20  
21 31 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 34 ▶sub _uniq {
Subroutine _uniq: called CC=1 SCAR=0.0
26 34 my %seen;
27 34 return grep { !$seen{$_}++ } @_;
28 }
29  
30 0 ▶sub _dirname { my ( $p ) = @_; ( my $d = $p ) =~ s{/[^/]*\z}{}; return length $d ? $d : '/' }
Subroutine _dirname: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
length $d ? : 0 0 0
31  
32 31 ▶sub apply {
Subroutine apply: called CC=3 SCAR=11.0
Pod documented
33 31 my ( $plan, %opts ) = @_;
34 31 my $lock_path = path_join( path_resolve( $opts{target_dir} ), 'skilletor.lock.json' );
35 31 my $old_lock = read_lock($lock_path);
36 31 my $landed = { order => [], by => {} };
37 31 my $res;
38 31 my $ok = eval { $res = _apply_plan( $plan, \%opts, $lock_path, $old_lock, $landed ); 1 };
39 31 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 6 25 31
40 6 my $err = $@;
41 6 ▶ _write_salvage_lock( $lock_path, $old_lock, $landed ) if @{ $landed->{order} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$landed->{"order"};} 6 0 6
42 6 die $err;
43 }
44 25 return $res;
45 }
46  
47 37 ▶sub _entry {
Subroutine _entry: called CC=6 SCAR=20.2
48 37 my ( $it, %fields ) = @_;
49 37 my $e = js_ordered( source => $it->{source}, version => $it->{version}, files => $fields{files} );
50 37 ▶ $e->{skipped} = $fields{skipped} if $fields{skipped};
Branch: 1 branch
BranchTrueFalseTotal
if $fields{"skipped"} 0 37 37
51 37 ▶ $e->{block} = JSON::MaybeXS::true() if $fields{block};
Branch: 1 branch
BranchTrueFalseTotal
if $fields{"block"} 0 37 37
52 0 ▶ $e->{via} = [ @{ $it->{via} } ] if $it->{via} && @{ $it->{via} };
Branch: 1 branch
BranchTrueFalseTotal
if $it->{"via"} and @{$it->{"via"};} 0 37 37
Condition33%1/3
$it->{"via"} and @{$it->{"via"};}
!ll&&!rl&&r
3700
MC/DC0%0/2
$it->{"via"} and @{$it->{"via"};}
$it->{"via"} @{$it->{"via"};}
Truth table33%1/3
A and B
A= $it->{"via"}B= @{$it->{"via"};}
ABresult
0X0
100
111
53 37 ▶ $e->{partial} = JSON::MaybeXS::true() if $fields{partial};
Branch: 1 branch
BranchTrueFalseTotal
if $fields{"partial"} 6 31 37
54 37 return $e;
55 }
56  
57 40 ▶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' ? : 7 33 40
Condition66%2/3
$e and ref $e->{"files"} eq "HASH"
!ll&&!rl&&r
3307
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 31 ▶sub _apply_plan {
Subroutine _apply_plan: called CC=67 SCAR=61.2
60 31 my ( $plan, $opts, $lock_path, $old_lock, $landed ) = @_;
61 31 my $target_dir = path_resolve( $opts->{target_dir} );
62 31 my $new_lock = js_ordered();
63 31 my $res = {
64 added => [], updated => [], removed => [], unchanged => [], skipped => [], conflicts => [], overwritten => [], written => [],
65 leftInPlace => [],
66 };
67 31 my ( %dirs_touched, @touched_roots );
68 31 ▶ 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'} ? : 31 3 34
69 31 ▶ my $touched = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
70 31 my ( $root ) = @_;
71 31 ▶ unless ( $dirs_touched{$root} ) { $dirs_touched{$root} = { order => [], set => {} }; push @touched_roots, $root }
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirs_touched{$root}) 25 6 31
72 31 return $dirs_touched{$root};
73 31 };
74  
75 31 my %planned = map { ( $_->{key} => 1 ) } @$plan;
76 31 ▶ my %keep = map { ( $_ => 1 ) } @{ $opts->{keep} // [] };
Condition100%2/2
$opts->{"keep"} // []
l!l
283
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 31 my $e = $old_lock->{$_};
81 0 ▶ !$planned{$_} && !$keep{$_} && !$e->{block} && !$e->{skipped} && %{ _files_of($e) };
Condition41%5/12
!($planned{$_} || $keep{$_} || $e->{'block'} || $e->{'skipped'}) && %{_files_of($e);}
!ll&&!rl&&r
1300
$planned{$_} || $keep{$_} || $e->{'block'} || $e->{'skipped'}
l!l&&r!l&&!r
1300
$planned{$_} or $keep{$_} or $e->{"block"}
l!l&&r!l&&!r
1300
$planned{$_} or $keep{$_}
l!l&&r!l&&!r
760
MC/DC0%0/5
!($planned{$_} || $keep{$_} || $e->{'block'} || $e->{'skipped'}) && %{_files_of($e);}
$planned{$_} $keep{$_} $e->{"block"} $e->{'skipped'} %{_files_of($e);}
Truth table33%2/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 31 for my $it (@$plan) {
85 37 ▶ Skilletor::Error::Apply->throw( 'invalid item name: '.$it->{name} ) unless $it->{name} =~ $NAME_RE;
Branch: 1 branch
BranchTrueFalseTotal
unless $it->{"name"} =~ /$NAME_RE/ 3 34 37
86 34 ▶ if ( $it->{inBlock} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($it->{"inBlock"}) 0 34 34
87 0 _record_block_item( $it, $old_lock->{ $it->{key} }, $new_lock, $res );
88 0 next;
89 }
90 34 my $root = $root_for->( $it->{key} );
91 34 ▶ if ( $it->{skipped} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($it->{"skipped"}) 0 34 34
92 # Owns no paths: delete only what the lock says was installed.
93 0 my @files = keys %{ _files_of( $old_lock->{ $it->{key} } ) };
94 0 _remove_item_files( $it->{key}, $root, \@files, $touched->($root), $res );
95 0 ▶ push @{ $res->{removed} }, $it->{key} if @files;
Branch: 1 branch
BranchTrueFalseTotal
if @files 0 0 0
96 0 push @{ $res->{skipped} }, $it->{key};
97 0 $new_lock->{ $it->{key} } = _entry( $it, files => js_ordered(), skipped => $it->{skipped} );
98 0 next;
99 }
100 # A previous skip entry owns nothing: the item counts as not yet installed.
101 34 ▶ 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'} ? : 7 27 34
Condition66%2/3
$$old_lock{$it->{"key"}} and not $$old_lock{$it->{"key"}}{"skipped"}
!ll&&!rl&&r
2707
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 34 my $ex_files = _files_of($existing);
103 0 my @holders = ( $ex_files, map { _files_of( $old_lock->{$_} ) } grep { $root_for->($_) eq $root } @leaving );
104 26 ▶ my $locked_hash = sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
105 26 my ( $rel ) = @_;
106 26 ▶ return $ex_files->{$rel} // _held( $root, $rel, \@holders );
Condition33%1/3
$ex_files->{$rel} // _held($root, $rel, \@holders)
l!l&&r!l&&!r
2600
MC/DC0%0/2
$ex_files->{$rel} // _held($root, $rel, \@holders)
$ex_files->{$rel} _held($root, $rel, \@holders)
Truth table33%1/3
A // B
A= $ex_files->{$rel}B= _held($root, $rel, \@holders)
ABresult
1X1
011
000
107 34 };
108 34 ▶ my $owned = sub { defined $locked_hash->( $_[0] ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
109 34 my $own = _own_path( $it->{key} );
110 34 my %out = map { ( $_->[0] => $_->[1] ) } @{ $it->{output} };
111 34 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 34 my ( @found, @delete_first );
115 0 ▶ my $conflict = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
116 0 my ( $p, $not_file, $replace ) = @_;
117 0 ▶ return if grep { $_->{path} eq $p } @found;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_->{"path"} eq $p;} @found 0 0 0
118 0 my $c = { key => $it->{key}, path => $p };
119 0 ▶ $c->{replace} = JSON::MaybeXS::true() if $replace;
Branch: 1 branch
BranchTrueFalseTotal
if $replace 0 0 0
120 0 ▶ $c->{notFile} = JSON::MaybeXS::true() if $not_file;
Branch: 1 branch
BranchTrueFalseTotal
if $not_file 0 0 0
121 0 push @found, $c;
122 0 ▶ push @delete_first, $p if $replace && !$not_file;
Branch: 1 branch
BranchTrueFalseTotal
if $replace and not $not_file 0 0 0
Condition0%0/3
$replace and not $not_file
!ll&&!rl&&r
000
MC/DC0%0/2
$replace and not $not_file
$replace not $not_file
Truth table0%0/3
A and not(B)
A= $replaceB= not $not_file
ABresult
0X0
100
111
123 34 };
124 34 ▶ my %claims = map { ( $_ => 1 ) } @{ $it->{claims} // [] };
Condition100%2/2
$it->{"claims"} // []
l!l
331
MC/DC100%1/1
$it->{"claims"} // []
$it->{"claims"}
Truth table100%2/2
A
A= $it->{"claims"}
Aresult
11
00
125 34 ▶ for my $rel ( _uniq( @{ $it->{claims} // [] }, ( map { $_->[0] } @{ $it->{output} } ), @removals ) ) {
Condition100%2/2
$it->{"claims"} // []
l!l
331
MC/DC100%1/1
$it->{"claims"} // []
$it->{"claims"}
Truth table100%2/2
A
A= $it->{"claims"}
Aresult
11
00
126 65 my $at = _inspect( $root, $rel, $own );
127 65 my $is_output = exists $out{$rel};
128 65 ▶ if ( $at->{kind} eq 'blocked' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($at->{'kind'} eq 'blocked') { } 0 65 65
elsif (not $is_output || $claims{$rel}) { } 0 65 65
elsif ($at->{'kind'} eq 'other' and $is_output || !&$owned($rel)) { } 0 65 65
elsif ($at->{'kind'} eq 'file' || $at->{'kind'} eq 'link' and not &$owned($rel)) { } 0 117 117
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
6230
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
6500
$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) ) {
Condition66%4/6
$at->{"kind"} eq "file" || $at->{"kind"} eq "link" and not &$owned($rel)
!ll&&!rl&&r
52130
$at->{"kind"} eq "file" or $at->{"kind"} eq "link"
l!l&&r!l&&!r
13052
MC/DC0%0/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 table40%2/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 0 $conflict->( $rel, 0, !$is_output );
142 }
143 }
144 0 ▶ my @blocking = grep { $_->{notFile} || !$opts->{force} } @found;
Condition0%0/3
$_->{'notFile'} || !$opts->{'force'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->{'notFile'} || !$opts->{'force'}
$_->{'notFile'} !$opts->{'force'}
Truth table0%0/3
A || not(B)
A= $_->{'notFile'}B= !$opts->{'force'}
ABresult
1X1
011
000
145 34 ▶ if (@blocking) {
Branch: 1 branch
BranchTrueFalseTotal
if (@blocking) 0 34 34
146 0 push @{ $res->{conflicts} }, @blocking;
147 0 ▶ $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 0 0
148 0 push @{ $res->{unchanged} }, $it->{key};
149 0 next;
150 }
151 34 _remove_file( _safe_join( $root, $_ ), $touched->($root) ) for @delete_first;
152  
153 34 my $entry_files = js_ordered();
154 34 my ( $wrote, $removed_file, $took_over ) = ( 0, 0, 0 );
155 43 ▶ my $land = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
156 43 my ( $rel, $hash ) = @_;
157 43 push @{ $res->{written} }, { key => $it->{key}, path => $rel };
158 43 ▶ unless ( $landed->{by}{ $it->{key} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($landed->{"by"}{$it->{"key"}}) 24 19 43
159 24 $landed->{by}{ $it->{key} } = { item => $it, files => js_ordered() };
160 24 push @{ $landed->{order} }, $it->{key};
161 }
162 43 $landed->{by}{ $it->{key} }{files}{$rel} = $hash;
163 34 };
164  
165 34 for my $pair ( @{ $it->{output} } ) {
166 59 my ( $rel, $bytes ) = @$pair;
167 59 my $abs = _safe_join( $root, $rel );
168 59 my $desired = hash_bytes($bytes);
169 59 ▶ my $executable = ( $it->{executable} // {} )->{$rel} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
+($it->{'executable'} // {})->{$rel} ? : 0 59 59
Condition50%1/2
$it->{"executable"} // {}
l!l
059
MC/DC0%0/1
$it->{"executable"} // {}
$it->{"executable"}
Truth table50%1/2
A
A= $it->{"executable"}
Aresult
11
00
170 59 my $st = _lstat($abs);
171 59 ▶ my $locked = $st ? $locked_hash->($rel) : $ex_files->{$rel};
Branch: 1 branch
BranchTrueFalseTotal
$st ? : 13 46 59
172 59 ▶ $took_over = 1 if defined $locked && !defined $ex_files->{$rel};
Branch: 1 branch
BranchTrueFalseTotal
if defined $locked and not defined $ex_files->{$rel} 0 59 59
Condition66%2/3
defined $locked and not defined $ex_files->{$rel}
!ll&&!rl&&r
46130
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 59 ▶ if ( $st && $st->{file} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st and $st->{'file'}) { } 13 46 59
Condition66%2/3
$st and $st->{"file"}
!ll&&!rl&&r
46013
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 13 my $disk = hash_bytes( path( encode_text($abs) )->slurp_raw );
176 13 ▶ if ( $disk eq $desired && is_executable( $st->{mode} ) == $executable ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($disk eq $desired and is_executable($st->{"mode"}) == $executable) 13 0 13
Condition33%1/3
$disk eq $desired and is_executable($st->{"mode"}) == $executable
!ll&&!rl&&r
0013
MC/DC0%0/2
$disk eq $desired and is_executable($st->{"mode"}) == $executable
$disk eq $desired is_executable($st->{"mode"}) == $executable
Truth table33%1/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 13 $entry_files->{$rel} = $desired;
179 13 ▶ $land->( $rel, $desired ) unless defined $locked; # adopted (force)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $locked 0 13 13
180 13 next;
181 }
182 0 atomic_write( encode_text($abs), $bytes, $executable );
183 0 ▶ 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 0 0
Condition0%0/6
defined $locked and $disk ne $desired and $disk ne $locked
!ll&&!rl&&r
000
defined $locked and $disk ne $desired
!ll&&!rl&&r
000
MC/DC0%0/3
defined $locked and $disk ne $desired and $disk ne $locked
defined $locked $disk ne $desired $disk ne $locked
Truth table0%0/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 46 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 43 43
Condition33%1/3
$st and defined $locked
!ll&&!rl&&r
4300
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 43 $wrote = 1;
193 43 $entry_files->{$rel} = $desired;
194 43 $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 31 my $outputs = [ { map { ( $_->[0] => '' ) } @{ $it->{output} } } ];
200 0 my @gone = grep { !defined _held( $root, $_, $outputs ) } @removals;
201 31 ▶ $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 31 31
202 31 ▶ $took_over = 1 if @gone < @removals;
Branch: 1 branch
BranchTrueFalseTotal
if @gone < @removals 0 31 31
203  
204 31 ▶ $new_lock->{ $it->{key} } = _entry( $it, files => $entry_files ) if %$entry_files;
Branch: 1 branch
BranchTrueFalseTotal
if %$entry_files 31 0 31
205  
206 31 ▶ if ( !$existing ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $existing) { } 24 7 31
elsif ($wrote or $removed_file or $took_over or $existing->{'partial'}) { } 3 4 7
207 24 ▶ if ( $wrote || $took_over ) { push @{ $res->{added} }, $it->{key} }
Branch: 1 branch
BranchTrueFalseTotal
if ($wrote or $took_over) { } 24 0 24
Condition33%1/3
$wrote or $took_over
l!l&&r!l&&!r
2400
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} ) {
Condition44%4/9
$wrote or $removed_file or $took_over or $existing->{"partial"}
l!l&&r!l&&!r
034
$wrote or $removed_file or $took_over
l!l&&r!l&&!r
007
$wrote or $removed_file
l!l&&r!l&&!r
007
MC/DC25%1/4
$wrote or $removed_file or $took_over or $existing->{"partial"}
$wrote $removed_file $took_over $existing->{"partial"}
Truth table40%2/5
A or B or C or D
A= $wroteB= $removed_fileC= $took_overD= $existing->{"partial"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
211 3 push @{ $res->{updated} }, $it->{key}; # a partial entry: the run that left it never reported it
212 }
213 else {
214 4 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 0 ▶ my $kept = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
221 0 my ( $root ) = @_;
222 0 ▶ return [ map { _files_of( $new_lock->{$_} ) } grep { !$new_lock->{$_}{block} && $root_for->($_) eq $root } keys %$new_lock ];
Condition0%0/3
!$new_lock->{$_}{'block'} && &$root_for($_) eq $root
!ll&&!rl&&r
000
MC/DC0%0/2
!$new_lock->{$_}{'block'} && &$root_for($_) eq $root
!$new_lock->{$_}{'block'} &$root_for($_) eq $root
Truth table0%0/3
not(A) && B
A= !$new_lock->{$_}{'block'}B= &$root_for($_) eq $root
ABresult
0X0
100
111
223 25 };
224 25 for my $key ( keys %$old_lock ) {
225 13 ▶ next if $planned{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $planned{$key} 7 6 13
226 6 ▶ if ( $keep{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($keep{$key}) 6 0 6
227 6 $new_lock->{$key} = $old_lock->{$key}; # preserved untouched
228 6 next;
229 }
230 0 ▶ unless ( $old_lock->{$key}{block} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($old_lock->{$key}{"block"}) 0 0 0
231 0 my $root = $root_for->($key);
232 0 my $holders = $kept->($root);
233 0 my @files = grep { !defined _held( $root, $_, $holders ) } keys %{ _files_of( $old_lock->{$key} ) };
234 0 _remove_item_files( $key, $root, \@files, $touched->($root), $res );
235 }
236 0 ▶ push @{ $res->{removed} }, $key unless $old_lock->{$key}{skipped}; # a skip entry had nothing installed
Branch: 1 branch
BranchTrueFalseTotal
unless $old_lock->{$key}{"skipped"} 0 0 0
237 }
238  
239 25 _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 25 ▶ my $empty_left = !%$new_lock && -e encode_text($lock_path);
Condition66%2/3
!%$new_lock && -e encode_text($lock_path)
!ll&&!rl&&r
1960
MC/DC0%0/2
!%$new_lock && -e encode_text($lock_path)
!%$new_lock -e encode_text($lock_path)
Truth table66%2/3
not(A) && B
A= !%$new_lockB= -e encode_text($lock_path)
ABresult
0X0
100
111
244 25 ▶ 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) 18 7 25
Condition66%2/3
$empty_left or serialize_lock($new_lock) ne serialize_lock($old_lock)
l!l&&r!l&&!r
0187
MC/DC50%1/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 table66%2/3
A or B
A= $empty_leftB= serialize_lock($new_lock) ne serialize_lock($old_lock)
ABresult
1X1
011
000
245 25 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 6 ▶sub _write_salvage_lock {
Subroutine _write_salvage_lock: called CC=5 SCAR=16.5
251 6 my ( $lock_path, $old_lock, $landed ) = @_;
252 0 my $lock = js_ordered( map { ( $_ => $old_lock->{$_} ) } keys %$old_lock );
253 6 for my $key ( @{ $landed->{order} } ) {
254 6 my ( $item, $files ) = @{ $landed->{by}{$key} }{qw( item files )};
255 6 ▶ 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 6 6
Condition33%1/3
$old_lock->{$key} and not $old_lock->{$key}{"skipped"}
!ll&&!rl&&r
600
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 6 my $merged = js_ordered( %{ _files_of($prev) } );
257 6 $merged->{$_} = $files->{$_} for keys %$files;
258 6 $lock->{$key} = _entry( $item, files => $merged, partial => 1 );
259 }
260 6 eval { write_lock( $lock_path, $lock ); 1 };
261 }
262  
263 # Lock and report a block section by its hash; no disk access.
264 0 ▶sub _record_block_item {
Subroutine _record_block_item: not called CC=7 SCAR=40.3
265 0 my ( $it, $prev, $new_lock, $res ) = @_;
266 0 ▶ my $had = ( $prev && !$prev->{skipped} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$prev && !$prev->{'skipped'} ? : 0 0 0
Condition0%0/3
$prev and not $prev->{"skipped"}
!ll&&!rl&&r
000
MC/DC0%0/2
$prev and not $prev->{"skipped"}
$prev not $prev->{"skipped"}
Truth table0%0/3
A and not(B)
A= $prevB= not $prev->{"skipped"}
ABresult
0X0
100
111
267 0 ▶ if ( $it->{skipped} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($it->{"skipped"}) 0 0 0
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 0 my $files = js_ordered( map { ( $_->[0] => hash_bytes( $_->[1] ) ) } @{ $it->{output} } );
274 0 $new_lock->{ $it->{key} } = _entry( $it, files => $files, block => 1 );
275 0 ▶ if ( !$had ) { push @{ $res->{added} }, $it->{key} }
Branch: 2 branches
BranchTrueFalseTotal
if (not $had) { } 0 0 0
elsif (Skilletor::JSON::js_stringify($prev->{'files'}) ne Skilletor::JSON::js_stringify($files)) { } 0 0 0
276 0 elsif ( Skilletor::JSON::js_stringify( $prev->{files} ) ne Skilletor::JSON::js_stringify($files) ) { push @{ $res->{updated} }, $it->{key} }
277 0 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 0 ▶sub _held {
Subroutine _held: not called CC=6 SCAR=37.4
283 0 my ( $root, $rel, $holders ) = @_;
284 0 my $k = name_key($rel);
285 0 for my $files (@$holders) {
286 0 for my $other ( keys %$files ) {
287 0 ▶ next if $other eq $rel || name_key($other) ne $k;
Branch: 1 branch
BranchTrueFalseTotal
if $other eq $rel or name_key($other) ne $k 0 0 0
Condition0%0/3
$other eq $rel or name_key($other) ne $k
l!l&&r!l&&!r
000
MC/DC0%0/2
$other eq $rel or name_key($other) ne $k
$other eq $rel name_key($other) ne $k
Truth table0%0/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 0 return undef;
292 }
293  
294 124 ▶sub _safe_join {
Subroutine _safe_join: called CC=3 SCAR=12.0
295 124 my ( $root, $rel ) = @_;
296 124 my $abs = path_resolve( path_join( $root, $rel ) );
297 124 ▶ 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 124 124
Condition33%1/3
$abs ne $root and index($abs, $root . '/') != 0
!ll&&!rl&&r
01240
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 124 return $abs;
299 }
300  
301 # The item's own path under its root: the lock key without a `<prefix>:`.
302 65 ▶sub _own_path {
Subroutine _own_path: called CC=4 SCAR=18.9
303 65 my ( $key ) = @_;
304 65 my ( $colon, $slash ) = ( index( $key, ':' ), index( $key, '/' ) );
305 65 ▶ return ( $colon != -1 && ( $slash == -1 || $colon < $slash ) ) ? substr( $key, $colon + 1 ) : $key;
Branch: 1 branch
BranchTrueFalseTotal
$colon != -1 && ($slash == -1 || $colon < $slash) ? : 0 65 65
Condition16%1/6
$colon != -1 and $slash == -1 || $colon < $slash
!ll&&!rl&&r
6500
$slash == -1 or $colon < $slash
l!l&&r!l&&!r
000
MC/DC0%0/3
$colon != -1 and $slash == -1 || $colon < $slash
$colon != -1 $slash == -1 $colon < $slash
Truth table25%1/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 148 ▶sub _lstat {
Subroutine _lstat: called CC=7 SCAR=20.7
310 148 my ( $abs ) = @_;
311 148 my @st = lstat encode_text($abs);
312 148 ▶ unless (@st) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@st) 98 50 148
313 98 ▶ return undef if $!{ENOENT} || $!{ENOTDIR};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"ENOENT"} or $!{"ENOTDIR"} 98 0 98
Condition33%1/3
$!{"ENOENT"} or $!{"ENOTDIR"}
l!l&&r!l&&!r
9800
MC/DC0%0/2
$!{"ENOENT"} or $!{"ENOTDIR"}
$!{"ENOENT"} $!{"ENOTDIR"}
Truth table33%1/3
A or B
A= $!{"ENOENT"}B= $!{"ENOTDIR"}
ABresult
1X1
011
000
314 0 die 'lstat '.$abs.': '.$!."\n";
315 }
316 50 ▶ return { link => ( -l _ ? 1 : 0 ), dir => ( -d _ ? 1 : 0 ), file => ( -f _ ? 1 : 0 ), mode => $st[2] };
Branch: 3 branches
BranchTrueFalseTotal
-l _ ? : 0 50 50
-d _ ? : 24 26 50
-f _ ? : 26 24 50
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 65 ▶sub _inspect {
Subroutine _inspect: called CC=12 SCAR=27.0
322 65 my ( $root, $rel, $own ) = @_;
323 65 my $abs = _safe_join( $root, $rel );
324 65 ▶ my @parts = split m{/}, ( $abs eq $root ? '' : substr( $abs, length($root) + 1 ) ), -1;
Branch: 1 branch
BranchTrueFalseTotal
$abs eq $root ? : 0 65 65
325 65 ▶ @parts = ('') unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 0 65 65
326 65 my @own_parts = split m{/}, $own, -1;
327 65 ▶ 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
6059
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 65 ▶ my $first = $under ? $#own_parts : $#parts;
Branch: 1 branch
BranchTrueFalseTotal
$under ? : 59 6 65
329 65 for my $i ( $first .. $#parts ) {
330 89 ▶ 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"} 37 52 89
331 37 ▶ if ( $i < $#parts ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i < $#parts) { } 24 13 37
elsif ($st->{'link'}) { } 0 13 13
332 24 ▶ 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 24 24
Condition33%1/3
$st->{"dir"} and not $st->{"link"}
!ll&&!rl&&r
0024
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 13 ▶ return { kind => $st->{file} ? 'file' : 'other' };
Branch: 1 branch
BranchTrueFalseTotal
$st->{'file'} ? : 13 0 13
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 31 ▶sub _remove_item_files {
Subroutine _remove_item_files: called CC=8 SCAR=37.9
347 31 my ( $key, $root, $files, $dirs, $res ) = @_;
348 31 my $own = _own_path($key);
349 31 my $removed = 0;
350 31 for my $rel (@$files) {
351 0 my $at = _inspect( $root, $rel, $own );
352 0 ▶ if ( $at->{kind} eq 'blocked' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($at->{'kind'} eq 'blocked') { } 0 0 0
elsif ($at->{'kind'} eq 'file' or $at->{'kind'} eq 'link') { } 0 0 0
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' ) {
Condition0%0/3
$at->{"kind"} eq "file" or $at->{"kind"} eq "link"
l!l&&r!l&&!r
000
MC/DC0%0/2
$at->{"kind"} eq "file" or $at->{"kind"} eq "link"
$at->{"kind"} eq "file" $at->{"kind"} eq "link"
Truth table0%0/3
A or B
A= $at->{"kind"} eq "file"B= $at->{"kind"} eq "link"
ABresult
1X1
011
000
358 0 _remove_file( _safe_join( $root, $rel ), $dirs );
359 0 $removed = 1;
360 }
361 }
362 31 return $removed;
363 }
364  
365 # Delete a file or link (never a directory, never through the final link).
366 0 ▶sub _remove_file {
Subroutine _remove_file: not called CC=7 SCAR=40.3
367 0 my ( $abs, $dirs ) = @_;
368 0 my $st = _lstat($abs);
369 0 ▶ return unless $st && ( $st->{link} || !$st->{dir} );
Branch: 1 branch
BranchTrueFalseTotal
unless $st and $st->{"link"} || !$st->{"dir"} 0 0 0
Condition0%0/6
$st and $st->{"link"} || !$st->{"dir"}
!ll&&!rl&&r
000
$st->{"link"} or not $st->{"dir"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$st and $st->{"link"} || !$st->{"dir"}
$st $st->{"link"} not $st->{"dir"}
Truth table0%0/4
A and B or not(C)
A= $stB= $st->{"link"}C= not $st->{"dir"}
ABCresult
0XX0
1000
11X1
1011
370 0 ▶ 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" 0 0 0
Condition0%0/3
unlink encode_text($abs) or $!{"ENOENT"}
l!l&&r!l&&!r
000
MC/DC0%0/2
unlink encode_text($abs) or $!{"ENOENT"}
unlink encode_text($abs) $!{"ENOENT"}
Truth table0%0/3
A or B
A= unlink encode_text($abs)B= $!{"ENOENT"}
ABresult
1X1
011
000
371 0 my $d = _dirname($abs);
372 0 ▶ push @{ $dirs->{order} }, $d unless $dirs->{set}{$d}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $dirs->{"set"}{$d}++ 0 0 0
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 19 ▶sub _prune_empty_dirs {
Subroutine _prune_empty_dirs: called CC=11 SCAR=47.3
378 19 my ( $dirs, $root ) = @_;
379 0 for my $start ( sort { length($b) <=> length($a) } @$dirs ) {
380 0 my $dir = $start;
381 0 ▶ while ( $dir ne $root && index( $dir, $root.'/' ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir ne $root and index($dir, $root . '/') == 0) 0 0 0
Condition0%0/3
$dir ne $root and index($dir, $root . '/') == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$dir ne $root and index($dir, $root . '/') == 0
$dir ne $root index($dir, $root . '/') == 0
Truth table0%0/3
A and B
A= $dir ne $rootB= index($dir, $root . '/') == 0
ABresult
0X0
100
111
382 0 my $st = _lstat($dir);
383 0 ▶ last unless $st && $st->{dir} && !$st->{link};
Branch: 1 branch
BranchTrueFalseTotal
unless $st and $st->{"dir"} and not $st->{"link"} 0 0 0
Condition0%0/6
$st and $st->{"dir"} and not $st->{"link"}
!ll&&!rl&&r
000
$st and $st->{"dir"}
!ll&&!rl&&r
000
MC/DC0%0/3
$st and $st->{"dir"} and not $st->{"link"}
$st $st->{"dir"} not $st->{"link"}
Truth table0%0/4
A and B and not(C)
A= $stB= $st->{"dir"}C= not $st->{"link"}
ABCresult
0XX0
10X0
1100
1111
384 0 ▶ opendir( my $dh, encode_text($dir) ) or last;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, encode_text($dir) or last 0 0 0
385 0 ▶ my $empty = !grep { $_ ne '.' && $_ ne '..' } readdir $dh;
Condition0%0/3
$_ ne '.' && $_ ne '..'
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne '.' && $_ ne '..'
$_ ne '.' $_ ne '..'
Truth table0%0/3
A && B
A= $_ ne '.'B= $_ ne '..'
ABresult
0X0
100
111
386 0 closedir $dh;
387 0 ▶ last unless $empty;
Branch: 1 branch
BranchTrueFalseTotal
unless $empty 0 0 0
388 0 ▶ rmdir encode_text($dir) or die 'rmdir '.$dir.': '.$!."\n";
Branch: 1 branch
BranchTrueFalseTotal
rmdir encode_text($dir) or die 'rmdir ' . $dir . ': ' . $! . "\n" 0 0 0
389 0 $dir = _dirname($dir);
390 }
391 }
392 }
393  
394 31 1;
395  
396 __END__
« Skilletor/ClaudeSettings.pm ↑ Summary Skilletor/Resolver.pm »