| 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
Condition0%0/3
defined $_[0] and $_[0] =~ /$NAME_RE/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | _write_salvage_lock( $lock_path, $old_lock, $landed ) if @{ $landed->{order} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 37 | ▶ | $e->{block} = JSON::MaybeXS::true() if $fields{block}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $e->{via} = [ @{ $it->{via} } ] if $it->{via} && @{ $it->{via} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$it->{"via"} and @{$it->{"via"};}
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"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 37 | ▶ | $e->{partial} = JSON::MaybeXS::true() if $fields{partial}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$e and ref $e->{"files"} eq "HASH"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // []
MC/DC100%1/1
$opts->{"keep"} // []
$opts->{"keep"}
Truth table100%2/2
A
A= $opts->{"keep"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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);}
$planned{$_} || $keep{$_} || $e->{'block'} || $e->{'skipped'}
$planned{$_} or $keep{$_} or $e->{"block"}
$planned{$_} or $keep{$_}
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);}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 34 | ▶ | if ( $it->{inBlock} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
$$old_lock{$it->{"key"}} and not $$old_lock{$it->{"key"}}{"skipped"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $c = { key => $it->{key}, path => $p }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $c->{replace} = JSON::MaybeXS::true() if $replace; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | $c->{notFile} = JSON::MaybeXS::true() if $not_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | push @found, $c; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | push @delete_first, $p if $replace && !$not_file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$replace and not $not_file
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 34 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 34 | ▶ | my %claims = map { ( $_ => 1 ) } @{ $it->{claims} // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$it->{"claims"} // []
MC/DC100%1/1
$it->{"claims"} // []
$it->{"claims"}
Truth table100%2/2
A
A= $it->{"claims"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 34 | ▶ | for my $rel ( _uniq( @{ $it->{claims} // [] }, ( map { $_->[0] } @{ $it->{output} } ), @removals ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$it->{"claims"} // []
MC/DC100%1/1
$it->{"claims"} // []
$it->{"claims"}
Truth table100%2/2
A
A= $it->{"claims"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$at->{"link"} or not &$owned($at->{"path"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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}
MC/DC0%0/2
$is_output || $claims{$rel}
$is_output
$claims{$rel}
Truth table66%2/3
A || B
A= $is_outputB= $claims{$rel}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
$is_output or not &$owned($rel)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
$at->{"kind"} eq "file" or $at->{"kind"} eq "link"
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $conflict->( $rel, 0, !$is_output ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | my @blocking = grep { $_->{notFile} || !$opts->{force} } @found; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'notFile'} || !$opts->{'force'}
MC/DC0%0/2
$_->{'notFile'} || !$opts->{'force'}
$_->{'notFile'}
!$opts->{'force'}
Truth table0%0/3
A || not(B)
A= $_->{'notFile'}B= !$opts->{'force'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 34 | ▶ | if (@blocking) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$it->{"executable"} // {}
MC/DC0%0/1
$it->{"executable"} // {}
$it->{"executable"}
Truth table50%1/2
A
A= $it->{"executable"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 59 | my $st = _lstat($abs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 59 | ▶ | my $locked = $st ? $locked_hash->($rel) : $ex_files->{$rel}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 59 | ▶ | $took_over = 1 if defined $locked && !defined $ex_files->{$rel}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $locked and not defined $ex_files->{$rel}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 59 | ▶ | if ( $st && $st->{file} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$st and $st->{"file"}
MC/DC50%1/2
$st and $st->{"file"}
$st
$st->{"file"}
Truth table66%2/3
A and B
A= $stB= $st->{"file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$disk eq $desired and is_executable($st->{"mode"}) == $executable
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
defined $locked and $disk ne $desired and $disk ne $locked
defined $locked and $disk ne $desired
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$st and defined $locked
MC/DC0%0/2
$st and defined $locked
$st
defined $locked
Truth table33%1/3
A and B
A= $stB= defined $locked
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 31 | ▶ | $took_over = 1 if @gone < @removals; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 31 | ▶ | $new_lock->{ $it->{key} } = _entry( $it, files => $entry_files ) if %$entry_files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 31 | ▶ | if ( !$existing ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 24 | ▶ | if ( $wrote || $took_over ) { push @{ $res->{added} }, $it->{key} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$wrote or $took_over
MC/DC0%0/2
$wrote or $took_over
$wrote
$took_over
Truth table33%1/3
A or B
A= $wroteB= $took_over
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"}
$wrote or $removed_file or $took_over
$wrote or $removed_file
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 25 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 25 | for my $key ( keys %$old_lock ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 13 | ▶ | next if $planned{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | ▶ | if ( $keep{$key} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 6 | $new_lock->{$key} = $old_lock->{$key}; # preserved untouched | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | unless ( $old_lock->{$key}{block} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 25 | ▶ | write_lock( $lock_path, $new_lock ) if $empty_left || serialize_lock($new_lock) ne serialize_lock($old_lock); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$empty_left or serialize_lock($new_lock) ne serialize_lock($old_lock)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$old_lock->{$key} and not $old_lock->{$key}{"skipped"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$prev and not $prev->{"skipped"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if ( $it->{skipped} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | push @{ $res->{removed} }, $it->{key} if $had; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$other eq $rel or name_key($other) ne $k
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | return $files->{$other} if same_file( _safe_join( $root, $other ), _safe_join( $root, $rel ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$abs ne $root and index($abs, $root . '/') != 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition16%1/6
$colon != -1 and $slash == -1 || $colon < $slash
$slash == -1 or $colon < $slash
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 98 | ▶ | return undef if $!{ENOENT} || $!{ENOTDIR}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$!{"ENOENT"} or $!{"ENOTDIR"}
MC/DC0%0/2
$!{"ENOENT"} or $!{"ENOTDIR"}
$!{"ENOENT"}
$!{"ENOTDIR"}
Truth table33%1/3
A or B
A= $!{"ENOENT"}B= $!{"ENOTDIR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 65 | ▶ | @parts = ('') unless @parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 65 | ▶ | my $first = $under ? $#own_parts : $#parts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 37 | ▶ | if ( $i < $#parts ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 24 | ▶ | return { kind => 'blocked', path => join( '/', @parts[ 0 .. $i ] ), link => $st->{link} } unless $st->{dir} && !$st->{link}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$st->{"dir"} and not $st->{"link"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | elsif ( $st->{link} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | return { kind => 'link' }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 13 | ▶ | return { kind => $st->{file} ? 'file' : 'other' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if ( $at->{link} && !grep { $_->{key} eq $key && $_->{path} eq $at->{path} } @{ $res->{leftInPlace} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$at->{"link"} and not grep({$_->{"key"} eq $key and $_->{"path"} eq $at->{"path"};} @{$$res{"leftInPlace"};})
$_->{'key'} eq $key && $_->{'path'} eq $at->{'path'}
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"};})
Truth table0%0/3
A && B
A= $_->{'key'} eq $keyB= $_->{'path'} eq $at->{'path'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$st and $st->{"link"} || !$st->{"dir"}
$st->{"link"} or not $st->{"dir"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | unlink encode_text($abs) or $!{ENOENT} or die 'unlink '.$abs.': '.$!."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
unlink encode_text($abs) or $!{"ENOENT"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my $d = _dirname($abs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | push @{ $dirs->{order} }, $d unless $dirs->{set}{$d}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$dir ne $root and index($dir, $root . '/') == 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my $st = _lstat($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | last unless $st && $st->{dir} && !$st->{link}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$st and $st->{"dir"} and not $st->{"link"}
$st and $st->{"dir"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | opendir( my $dh, encode_text($dir) ) or last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | my $empty = !grep { $_ ne '.' && $_ ne '..' } readdir $dh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_ ne '.' && $_ ne '..'
MC/DC0%0/2
$_ ne '.' && $_ ne '..'
$_ ne '.'
$_ ne '..'
Truth table0%0/3
A && B
A= $_ ne '.'B= $_ ne '..'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | closedir $dh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | ▶ | last unless $empty; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | rmdir encode_text($dir) or die 'rmdir '.$dir.': '.$!."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $dir = _dirname($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 31 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||