| 1 | package Skilletor::Source::Url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: A url source: an https .tar.gz, conditional GET, staged swap into the shared cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 35 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 35 | ▶ | use Digest::SHA qw( sha256_hex ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 35 | ▶ | use Fcntl (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 35 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 35 | ▶ | use Path::Tiny qw( path ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 35 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 35 | ▶ | use Skilletor::Cache qw( url_cache_dir ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 35 | ▶ | use Skilletor::Error::Source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 35 | ▶ | use Skilletor::Error::Tar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 35 | ▶ | use Skilletor::FSUtil qw( encode_text path_join path_resolve read_text ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 35 | ▶ | use Skilletor::Gzip qw( gunzip_sync inflate_sync ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 35 | ▶ | use Skilletor::Tar qw( parse_tar strip_top_level is_reserved VERSION_FILE ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 35 | ▶ | use Skilletor::URL qw( parse_url ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 35 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 35 | with 'Skilletor::Role::Source'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 35 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # The first line of a version file: the format of its tree. 2: an entry's owner executable bit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # is kept. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 35 | ▶ | use constant CACHE_FORMAT => 'format 2'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # A stage or backup tree the publication makes next to a cache dir. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 35 | my $LEFTOVER = qr/\A([0-9a-f]{16})\.(stage|backup)-[A-Za-z0-9]{6}\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 35 | my @TEMP_CHARS = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 35 | has url => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 35 | has cache_root => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | has timeout_ms => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 15 | ▶ | default => sub { 60_000 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 35 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # Tests only: permit http://127.0.0.1 and http://localhost. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | has allow_http => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 35 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 35 | has http => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 10 | ▶ | sub _build_http { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_http: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 10 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 10 | return HTTP::Tiny->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | agent => 'node', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | timeout => $self->timeout_ms / 1000, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | verify_SSL => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | max_redirect => 20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 21 | ▶ | sub cache_dir { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 21 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 21 | return url_cache_dir( $self->cache_root, $self->url ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 28 | ▶ | sub _assert_scheme { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_assert_scheme: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 28 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 28 | ▶ | my $u = parse_url( $self->url ) or Skilletor::Error::Source->throw('Invalid URL'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 27 | ▶ | return if $u->{protocol} eq 'https:'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 26 | ▶ | my $local_http = $u->{protocol} eq 'http:' && ( $u->{hostname} eq '127.0.0.1' || $u->{hostname} eq 'localhost' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$u->{'protocol'} eq 'http:' && ($u->{'hostname'} eq '127.0.0.1' || $u->{'hostname'} eq 'localhost')
$u->{"hostname"} eq "127.0.0.1" or $u->{"hostname"} eq "localhost"
MC/DC33%1/3
$u->{'protocol'} eq 'http:' && ($u->{'hostname'} eq '127.0.0.1' || $u->{'hostname'} eq 'localhost')
$u->{'protocol'} eq 'http:'
$u->{"hostname"} eq "127.0.0.1"
$u->{"hostname"} eq "localhost"
Truth table50%2/4
A && B or C
A= $u->{'protocol'} eq 'http:'B= $u->{"hostname"} eq "127.0.0.1"C= $u->{"hostname"} eq "localhost"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 26 | ▶ | return if $self->allow_http && $local_http; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->allow_http and $local_http
MC/DC100%2/2
$self->allow_http and $local_http
$self->allow_http
$local_http
Truth table100%3/3
A and B
A= $self->allow_httpB= $local_http
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | Skilletor::Error::Source->throw( 'url source must be https://: '.$self->url ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 4 | ▶ | sub _fail { Skilletor::Error::Source->throw( $_[1] ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # A request with the headers Node's fetch sends, the body decoded as fetch decodes it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 24 | ▶ | sub _request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_request: called CC=11 SCAR=25.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 24 | my ( $self, $method, $headers ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 24 | my %h = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | accept => '*/*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 'accept-language' => '*', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 'sec-fetch-mode' => 'cors', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 'accept-encoding' => 'gzip, deflate', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | %$headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 24 | ▶ | if ( exists $headers->{'If-None-Match'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | $h{pragma} = 'no-cache'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 8 | $h{'cache-control'} = 'no-cache'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 24 | my $res = $self->http->request( $method, $self->url, { headers => \%h } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 24 | ▶ | if ( $res->{status} == 599 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | $self->_fail( ( $res->{content} // '' ) =~ /timed? ?out/i ? 'This operation was aborted' : 'fetch failed' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$res->{"content"} // ""
MC/DC0%0/1
$res->{"content"} // ""
$res->{"content"}
Truth table50%1/2
A
A= $res->{"content"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 23 | ▶ | my $encoding = lc( _header( $res, 'content-encoding' ) // '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
_header($res, "content-encoding") // ""
MC/DC0%0/1
_header($res, "content-encoding") // ""
_header($res, "content-encoding")
Truth table50%1/2
A
A= _header($res, "content-encoding")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 23 | ▶ | if ( $method eq 'GET' && length( $res->{content} // '' ) && $encoding =~ /\A(?:x-)?(gzip|deflate)\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition87%7/8
$method eq "GET" and length($res->{"content"} // "") and $encoding =~ /\A(?:x-)?(gzip|deflate)\z/
$method eq "GET" and length($res->{"content"} // "")
$res->{"content"} // ""
MC/DC0%0/3
$method eq "GET" and length($res->{"content"} // "") and $encoding =~ /\A(?:x-)?(gzip|deflate)\z/
$method eq "GET"
$res->{"content"}
$encoding =~ /\A(?:x-)?(gzip|deflate)\z/
Truth table75%3/4
A and B and C
A= $method eq "GET"B= $res->{"content"}C= $encoding =~ /\A(?:x-)?(gzip|deflate)\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $res->{content} = $1 eq 'gzip' ? gunzip_sync( $res->{content} ) : inflate_sync( $res->{content} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 23 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 42 | ▶ | sub _header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_header: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 42 | my ( $res, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 42 | my $v = $res->{headers}{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 42 | ▶ | return undef unless defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 17 | ▶ | return ref $v eq 'ARRAY' ? join( ', ', @$v ) : $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 9 | ▶ | sub _msg { my ( $err ) = @_; return blessed $err && $err->can('message') ? $err->message : "$err" =~ s/ at \S+ line \d+\.?\n?\z//r } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_msg: called CC=3 SCAR=13.1
Branch: 1 branch
Condition33%1/3
builtin::blessed($err) and $err->can("message")
MC/DC0%0/2
builtin::blessed($err) and $err->can("message")
builtin::blessed($err)
$err->can("message")
Truth table33%1/3
A and B
A= builtin::blessed($err)B= $err->can("message")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 21 | ▶ | sub resolve { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=17 SCAR=28.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 21 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 21 | $self->_assert_scheme; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 19 | my $dir = $self->cache_dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 19 | my $result = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 19 | my $cached = $self->cache_version($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 19 | ▶ | my $etag = ( defined $cached && $cached =~ /\Aetag:(.*)\z/s ) ? $1 : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $cached and $cached =~ /\Aetag:(.*)\z/s
MC/DC50%1/2
defined $cached and $cached =~ /\Aetag:(.*)\z/s
defined $cached
$cached =~ /\Aetag:(.*)\z/s
Truth table66%2/3
A and B
A= defined $cachedB= $cached =~ /\Aetag:(.*)\z/s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 19 | ▶ | my $res = $self->_request( GET => defined $etag ? { 'If-None-Match' => $etag } : {} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 18 | ▶ | return +{ dir => $dir, version => $cached } if $res->{status} == 304 && defined $etag; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$res->{"status"} == 304 and defined $etag
MC/DC50%1/2
$res->{"status"} == 304 and defined $etag
$res->{"status"} == 304
defined $etag
Truth table66%2/3
A and B
A= $res->{"status"} == 304B= defined $etag
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 17 | ▶ | $self->_fail( 'HTTP '.$res->{status} ) unless $res->{status} >= 200 && $res->{status} <= 299; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$res->{"status"} >= 200 and $res->{"status"} <= 299
MC/DC50%1/2
$res->{"status"} >= 200 and $res->{"status"} <= 299
$res->{"status"} >= 200
$res->{"status"} <= 299
Truth table66%2/3
A and B
A= $res->{"status"} >= 200B= $res->{"status"} <= 299
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 14 | ▶ | my $body = $res->{content} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$res->{"content"} // ""
MC/DC0%0/1
$res->{"content"} // ""
$res->{"content"}
Truth table50%1/2
A
A= $res->{"content"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 14 | my $res_etag = _header( $res, 'etag' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 14 | ▶ | my $version = ( defined $res_etag && length $res_etag ) ? 'etag:'.$res_etag : 'sha256:'.sha256_hex($body); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $res_etag and length $res_etag
MC/DC50%1/2
defined $res_etag and length $res_etag
defined $res_etag
length $res_etag
Truth table66%2/3
A and B
A= defined $res_etagB= length $res_etag
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 14 | my @entries = grep { !is_reserved( $_->{name} ) } @{ strip_top_level( parse_tar( gunzip_sync($body) ) ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | my $warning = $self->_publish( $dir, \@entries, $version ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 8 | ▶ | +{ dir => $dir, version => $version, ( defined $warning ? ( warning => $warning ) : () ) }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 19 | ▶ | return $result if $result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 10 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 10 | ▶ | if ( blessed $err && $err->isa('Skilletor::Error::Tar') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($err) and $err->isa("Skilletor::Error::Tar")
MC/DC50%1/2
builtin::blessed($err) and $err->isa("Skilletor::Error::Tar")
builtin::blessed($err)
$err->isa("Skilletor::Error::Tar")
Truth table66%2/3
A and B
A= builtin::blessed($err)B= $err->isa("Skilletor::Error::Tar")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | Skilletor::Error::Source->throw( 'url source '.$self->url.' failed: '.$err->message ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 9 | ▶ | if ( -e $dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | ▶ | dir => $dir, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->cache_version($dir) // "unknown"
MC/DC100%1/1
$self->cache_version($dir) // "unknown"
$self->cache_version($dir)
Truth table100%2/2
A
A= $self->cache_version($dir)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | version => $self->cache_version($dir) // 'unknown', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | warning => 'download failed for '.$self->url.', using cache ('._msg($err).')', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | Skilletor::Error::Source->throw( 'url source '.$self->url.' failed: '._msg($err) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # The cache as it is, without a request: what resolve serves when a download fails, without | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # the warning. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | sub cached { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cached: called CC=3 SCAR=13.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | $self->_assert_scheme; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | my $dir = $self->cache_dir; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | Skilletor::Error::Source->throw( 'url source '.$self->url.' is not in the cache (no fetch)' ) unless -e $dir; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return { dir => $dir, version => $self->cache_version($dir) // 'unknown' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->cache_version($dir) // "unknown"
MC/DC0%0/1
$self->cache_version($dir) // "unknown"
$self->cache_version($dir)
Truth table0%0/2
A
A= $self->cache_version($dir)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 6 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | my ( $self, $cached_version ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 6 | $self->_assert_scheme; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | my $res = $self->_request( HEAD => {} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | my $etag = _header( $res, 'etag' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | ▶ | return 1 unless defined $etag && length $etag && defined $cached_version && $cached_version =~ /\Aetag:/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
defined $etag and length $etag and defined $cached_version and $cached_version =~ /\Aetag:/
defined $etag and length $etag and defined $cached_version
defined $etag and length $etag
MC/DC75%3/4
defined $etag and length $etag and defined $cached_version and $cached_version =~ /\Aetag:/
defined $etag
length $etag
defined $cached_version
$cached_version =~ /\Aetag:/
Truth table80%4/5
A and B and C and D
A= defined $etagB= length $etagC= defined $cached_versionD= $cached_version =~ /\Aetag:/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | ▶ | return $etag ne substr( $cached_version, 5 ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # The version of the tree in a cache dir; undef without a readable, well-formed one of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # current format. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 27 | ▶ | sub cache_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cache_version: called CC=7 SCAR=20.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 27 | my ( $self, $dir ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 27 | my $text = eval { read_text( path_join( $dir, VERSION_FILE ) ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 27 | ▶ | return undef unless defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 16 | my ( $format, $version, @rest ) = split /\n/, $text, -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 16 | ▶ | return undef if !defined $format || $format ne CACHE_FORMAT || @rest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not defined $format or $format ne "format 2" or @rest
not defined $format or $format ne "format 2"
MC/DC33%1/3
not defined $format or $format ne "format 2" or @rest
not defined $format
$format ne "format 2"
@rest
Truth table50%2/4
not(A) or B or C
A= not defined $formatB= $format ne "format 2"C= @rest
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 14 | ▶ | return ( defined $version && $version =~ /\A(?:etag|sha256):[^\r\n]+\z/ ) ? $version : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $version and $version =~ /\A(?:etag|sha256):[^\r\n]+\z/
MC/DC0%0/2
defined $version and $version =~ /\A(?:etag|sha256):[^\r\n]+\z/
defined $version
$version =~ /\A(?:etag|sha256):[^\r\n]+\z/
Truth table33%1/3
A and B
A= defined $versionB= $version =~ /\A(?:etag|sha256):[^\r\n]+\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 10 | ▶ | sub _mkdtemp { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mkdtemp: called CC=4 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 10 | my ( $self, $prefix ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 10 | for ( 1 .. 100 ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 10 | my $path = $prefix.join '', map { $TEMP_CHARS[ int rand @TEMP_CHARS ] } 1 .. 6; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 10 | ▶ | return $path if mkdir $path, 0700; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | die 'mkdtemp '.$prefix.': '.$! unless $!{EEXIST}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | die 'mkdtemp '.$prefix.': no free name'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 8 | ▶ | sub _write_entries { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_entries: called CC=8 SCAR=22.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 8 | my ( $self, $dir, $entries ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 8 | my $root = path_resolve($dir); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 8 | for my $e (@$entries) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 16 | my $dest = path_resolve( path_join( $dir, $e->{name} ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 16 | ▶ | if ( $dest ne $root && index( $dest, $root.'/' ) != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$dest ne $root and index($dest, $root . '/') != 0
MC/DC0%0/2
$dest ne $root and index($dest, $root . '/') != 0
$dest ne $root
index($dest, $root . '/') != 0
Truth table33%1/3
A and B
A= $dest ne $rootB= index($dest, $root . '/') != 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | Skilletor::Error::Tar->throw( 'unsafe tar entry (escapes target): '.$e->{name} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 16 | my $bytes_dest = encode_text($dest); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 16 | ▶ | if ( $e->{type} eq 'dir' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | path($bytes_dest)->mkpath; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 16 | path($bytes_dest)->parent->mkpath; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 16 | ▶ | sysopen( my $fh, $bytes_dest, Fcntl::O_WRONLY() | Fcntl::O_CREAT() | Fcntl::O_TRUNC(), $e->{executable} ? 0777 : 0666 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | or die 'open '.$dest.': '.$!."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 16 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 16 | print {$fh} $e->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 16 | ▶ | close $fh or die 'close '.$dest.': '.$!."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # Extract completely, with the tree's version inside it, before replacing the cache; every | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # rename moves tree and version together. Returns the cleanup warning, if any. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 8 | ▶ | sub _publish { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_publish: called CC=15 SCAR=31.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 8 | my ( $self, $dir, $entries, $version ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 8 | path($dir)->parent->mkpath; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 8 | my $staging = $self->_mkdtemp( $dir.'.stage-' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 8 | my ( $backup, $old_moved, $published ) = ( undef, 0, 0 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 8 | my @cleanup_warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 8 | my $ok = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 8 | $self->_write_entries( $staging, $entries ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | path( $staging, VERSION_FILE )->spew_raw( encode_text( CACHE_FORMAT."\n".$version ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 8 | ▶ | if ( -e $dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # A rename cannot replace a nonempty directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | $backup = $self->_mkdtemp( $dir.'.backup-' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | ▶ | rename $dir, path_join( $backup, 'tree' ) or die 'rename '.$dir.': '.$!."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | $old_moved = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 8 | ▶ | unless ( rename $staging, $dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $err = $!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ($old_moved) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ( rename path_join( $backup, 'tree' ), $dir ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $old_moved = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | die 'cache publication failed ('.$err.'); restoration failed ('.$!.'); last good cache remains at ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | .path_join( $backup, 'tree' )."\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | die 'rename '.$staging.': '.$err."\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # Commit point: cleanup must not turn new bytes into an old-version fallback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 8 | $published = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 8 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # Keep the backup when restoration failed; the sweep puts it back. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 8 | ▶ | my @obsolete = ( $staging, ( $backup && ( !$old_moved || $published ) ? ($backup) : () ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$backup and !$old_moved || $published
not $old_moved or $published
MC/DC33%1/3
$backup and !$old_moved || $published
$backup
not $old_moved
$published
Truth table50%2/4
A and not(B) or C
A= $backupB= not $old_movedC= $published
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 8 | for my $p (@obsolete) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 10 | ▶ | next unless -e $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 2 | my $removed = eval { path($p)->remove_tree( { safe => 0 } ); 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | ▶ | push @cleanup_warnings, 'cache cleanup failed for '.$p.' ('._msg($@).')' unless $removed && !-e $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$removed and not -e $p
MC/DC0%0/2
$removed and not -e $p
$removed
not -e $p
Truth table33%1/3
A and not(B)
A= $removedB= not -e $p
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 8 | ▶ | die $err unless $ok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 8 | ▶ | return @cleanup_warnings ? join( '; ', @cleanup_warnings ) : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # Clear what a run that failed or died left of an update: a stage tree goes; a backup whose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # cache dir is missing holds the last good cache and is renamed back; any other backup goes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # Only safe while no resolve runs – the caller holds the sync lock. Never throws. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 350 | ▶ | sub sweep_cache { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sweep_cache: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 350 | my ( $class, $cache_root ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 350 | ▶ | opendir( my $dh, $cache_root ) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 68 | my @names = sort readdir $dh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 68 | closedir $dh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 68 | for my $name (@names) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 208 | ▶ | my ( $hash, $kind ) = $name =~ $LEFTOVER or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 3 | my $p = path_join( $cache_root, $name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 3 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | ▶ | if ( $kind eq 'backup' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | my $dir = path_join( $cache_root, $hash ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | my $tree = path_join( $p, 'tree' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 2 | ▶ | rename $tree, $dir if !-e $dir && lstat($tree) && -d _; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
not -e $dir and lstat $tree and -d _
not -e $dir and lstat $tree
MC/DC33%1/3
not -e $dir and lstat $tree and -d _
not -e $dir
lstat $tree
-d _
Truth table50%2/4
not(A) and B and C
A= not -e $dirB= lstat $treeC= -d _
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 3 | path($p)->remove_tree( { safe => 0 } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 68 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 35 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||