blib/lib/Langertha/Holmgang/Sim/Linux/Backup.pm

filter: Statementstmt 90.2% 509 / 564 Branchbran 70.4% 296 / 420 Conditioncond 57.8% 136 / 235 MC/DCmcdc 27.2% 36 / 132 Subroutinesub 90.4% 38 / 42 Podpod 100% 6 / 6 totaltotal 72.9% 1021 / 1399 CC 340 SCAR 48.7
CC
340
Cov
77%
restic
218.0
tar
197.5
rsync
148.8
CRAP 130.7
« blib/lib/Langertha/Holmgang/Structure.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Dns.pm »
1 package Langertha::Holmgang::Sim::Linux::Backup;
2 # ABSTRACT: Backup and restore on a simulated Linux server — tar, rsync, restic, sha256sum
3  
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Time::Local ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 our $VERSION = '0.001';
14  
15  
16 8 my $T = JSON::MaybeXS::true();
17 87 ▶sub _lx { 'Langertha::Holmgang::Sim::Linux' }
Subroutine _lx: called CC=1 SCAR=0.0
18 87 ▶sub _L { my $n = shift; return _lx()->can($n)->(@_) }
Subroutine _L: called CC=1 SCAR=0.0
19  
20 11 ▶sub _cwd { $Langertha::Holmgang::Sim::Linux::CWD_DIR }
Subroutine _cwd: called CC=1 SCAR=0.0
21  
22 68 ▶sub _abs {
Subroutine _abs: called CC=5 SCAR=16.7
23 68 my ($p) = @_;
24 68 ▶ return $p if $p =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ m[\A/] 66 2 68
25 2 ▶ my $c = _cwd() // '/root';
Condition50%1/2
_cwd() // "/root"
l!l
20
MC/DC0%0/1
_cwd() // "/root"
_cwd()
Truth table50%1/2
A
A= _cwd()
Aresult
11
00
26 2 $p =~ s{\A\./}{};
27 2 ▶ return $p eq '.' ? $c : ( $c eq '/' ? "/$p" : "$c/$p" );
Branch: 2 branches
BranchTrueFalseTotal
$p eq '.' ? : 0 2 2
$c eq '/' ? : 0 2 2
28 }
29  
30 22 ▶sub _now_text { 'Oct 20 12:00' }
Subroutine _now_text: called CC=1 SCAR=0.0
31  
32 # Kopie eines Eintrags; erhalten (-a/-p, tar/restic als root) oder neu (root, umask 022)
33  
34 49 ▶sub copy_entry {
Subroutine copy_entry: called CC=5 SCAR=16.1
Pod documented
35 49 my ( $e, $keep ) = @_;
36 49 ▶ my %n = ref $e eq 'HASH' ? %$e : ( content => $e );
Branch: 1 branch
BranchTrueFalseTotal
ref $e eq 'HASH' ? : 46 3 49
37 49 ▶ delete @n{qw( open_by tar )} if !$n{tar};
Branch: 1 branch
BranchTrueFalseTotal
unless $n{"tar"} 48 1 49
38 49 delete $n{open_by};
39 49 ▶ unless ($keep) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($keep) 17 32 49
40 17 $n{owner} = 'root';
41 17 $n{group} = 'root';
42 17 ▶ $n{mode} = sprintf '%04o', oct( $n{mode} // '0644' ) & ~022;
Condition100%2/2
$n{"mode"} // "0644"
l!l
125
MC/DC100%1/1
$n{"mode"} // "0644"
$n{"mode"}
Truth table100%2/2
A
A= $n{"mode"}
Aresult
11
00
43 17 $n{mtime} = _now_text();
44 }
45 49 return \%n;
46 }
47  
48 57 ▶sub _entry { my ( $dev, $p ) = @_; my $e = ( $dev->{files} || {} )->{$p}; return undef unless defined $e; return ref $e eq 'HASH' ? $e : { content => $e } }
Subroutine _entry: called CC=4 SCAR=14.2
Branch: 2 branches
BranchTrueFalseTotal
unless defined $e 9 48 57
ref $e eq 'HASH' ? : 48 0 48
Condition50%1/2
$$dev{'files'} || {}
l!l
570
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
49  
50 24 ▶sub _put {
Subroutine _put: called CC=4 SCAR=15.0
51 24 my ( $dev, $path, $e ) = @_;
52 24 ▶ my $old = ( $dev->{files} || {} )->{$path};
Condition50%1/2
$$dev{'files'} || {}
l!l
240
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
53 0 ▶ if ( ref $old eq 'HASH' && $old->{open_by} ) { $e = { %$e, open_by => $old->{open_by} } }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $old eq "HASH" and $$old{"open_by"}) 0 24 24
Condition66%2/3
ref $old eq "HASH" and $$old{"open_by"}
!ll&&!rl&&r
2130
MC/DC0%0/2
ref $old eq "HASH" and $$old{"open_by"}
ref $old eq "HASH" $$old{"open_by"}
Truth table66%2/3
A and B
A= ref $old eq "HASH"B= $$old{"open_by"}
ABresult
0X0
100
111
54 24 $dev->{files}{$path} = $e;
55 24 return;
56 }
57  
58 # --- tar ---------------------------------------------------------------------------
59  
60 4 ▶sub _tar_glob {
Subroutine _tar_glob: called CC=1 SCAR=0.0
61 4 my ($g) = @_;
62 4 ( my $re = quotemeta $g ) =~ s/\\\*/.*/g;
63 4 $re =~ s/\\\?/./g;
64 4 return qr/\A$re(?:\/.*)?\z/;
65 }
66  
67 # --exclude wie GNU tar (nicht verankert): das Muster passt auf den ganzen Namen oder auf
68 # ein Stueck ab einer Komponente (cache trifft daten/cache und alles darunter)
69 29 ▶sub _tar_excluded {
Subroutine _tar_excluded: called CC=3 SCAR=11.0
70 29 my ( $rel, @ex ) = @_;
71 29 my @seg = split m{/}, $rel;
72 29 for my $x (@ex) {
73 4 ( my $pat = $x ) =~ s{\A(?:\./|/+)}{}; # wie das Mitglied: ohne ./ und fuehrendes /
74 4 $pat =~ s{/+\z}{};
75 4 my $re = _tar_glob($pat);
76 4 ▶ return 1 if grep { join( '/', @seg[ $_ .. $#seg ] ) =~ $re } 0 .. $#seg;
Branch: 1 branch
BranchTrueFalseTotal
if grep {join("/", @seg[$_ .. $#seg]) =~ /$re/;} 0 .. $#seg 2 2 4
77 }
78 27 return 0;
79 }
80  
81  
82 16 ▶sub tar {
Subroutine tar: called CC=94 SCAR=52.9
Pod documented
83 16 my ( $dev, $av, $ctx ) = @_;
84 16 my @a = @$av;
85 16 my ( $mode, $file, $dir, $strip, $verbose, $keep, $stdout, $remove, @lists, @ex, @mem );
86 16 my $first = 1;
87 16 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 31 16 47
88 31 my $x = shift @a;
89 31 ▶ if ( $first && $x =~ /\A[a-zA-Z]+\z/ && $x =~ /[cxt]/ ) { $x = "-$x" }
Branch: 1 branch
BranchTrueFalseTotal
if ($first and $x =~ /\A[a-zA-Z]+\z/ and $x =~ /[cxt]/) 2 29 31
Condition83%5/6
$first and $x =~ /\A[a-zA-Z]+\z/ and $x =~ /[cxt]/
!ll&&!rl&&r
2902
$first and $x =~ /\A[a-zA-Z]+\z/
!ll&&!rl&&r
15142
MC/DC66%2/3
$first and $x =~ /\A[a-zA-Z]+\z/ and $x =~ /[cxt]/
$first $x =~ /\A[a-zA-Z]+\z/ $x =~ /[cxt]/
Truth table75%3/4
A and B and C
A= $firstB= $x =~ /\A[a-zA-Z]+\z/C= $x =~ /[cxt]/
ABCresult
0XX0
10X0
1100
1111
90 31 $first = 0;
91 0 ▶ if ( $x =~ /\A--(create|extract|get|list)\z/ ) { $mode = { create => 'c', extract => 'x', get => 'x', list => 't' }->{$1} }
Branch: 16 branches
BranchTrueFalseTotal
if ($x =~ /\A--(create|extract|get|list)\z/) { } 0 31 31
elsif ($x =~ /\A--file=(.+)\z/) { } 0 31 31
elsif ($x eq '--file') { } 0 31 31
elsif ($x =~ /\A--directory=(.+)\z/) { } 0 31 31
elsif ($x eq '--directory' or $x eq '-C') { } 3 28 31
elsif ($x =~ /\A--strip-components=(\d+)\z/) { } 0 28 28
elsif ($x =~ /\A--exclude=(.+)\z/) { } 2 26 28
elsif ($x eq '--exclude') { } 0 26 26
elsif ($x eq '--keep-old-files') { } 0 26 26
elsif ($x eq '--to-stdout') { } 0 26 26
elsif ($x eq '--verbose') { } 0 26 26
elsif ($x =~ /\A--files-from=(.+)\z/) { } 1 25 26
elsif ($x eq '--files-from') { } 0 25 25
elsif ($x eq '--remove-files') { } 1 24 25
elsif ($x =~ /\A--/) { } 0 24 24
elsif ($x =~ /\A-([a-zA-Z]+)\z/) { } 17 7 24
92 0 elsif ( $x =~ /\A--file=(.+)\z/ ) { $file = $1 }
93 0 elsif ( $x eq '--file' ) { $file = shift @a }
94 0 elsif ( $x =~ /\A--directory=(.+)\z/ ) { $dir = $1 }
95 3 ▶ elsif ( $x eq '--directory' || $x eq '-C' ) { $dir = shift @a }
Condition66%2/3
$x eq "--directory" or $x eq "-C"
l!l&&r!l&&!r
0328
MC/DC50%1/2
$x eq "--directory" or $x eq "-C"
$x eq "--directory" $x eq "-C"
Truth table66%2/3
A or B
A= $x eq "--directory"B= $x eq "-C"
ABresult
1X1
011
000
96 0 elsif ( $x =~ /\A--strip-components=(\d+)\z/ ) { $strip = $1 }
97 2 elsif ( $x =~ /\A--exclude=(.+)\z/ ) { push @ex, $1 }
98 0 elsif ( $x eq '--exclude' ) { push @ex, shift @a }
99 0 elsif ( $x eq '--keep-old-files' ) { $keep = 1 }
100 0 elsif ( $x eq '--to-stdout' ) { $stdout = 1 }
101 0 elsif ( $x eq '--verbose' ) { $verbose = 1 }
102 1 elsif ( $x =~ /\A--files-from=(.+)\z/ ) { push @lists, $1 }
103 0 elsif ( $x eq '--files-from' ) { push @lists, shift @a }
104 1 elsif ( $x eq '--remove-files' ) { $remove = 1 }
105 elsif ( $x =~ /\A--/ ) { }
106 elsif ( $x =~ /\A-([a-zA-Z]+)\z/ ) {
107 17 my @f = split //, $1;
108 17 ▶ while ( defined( my $c = shift @f ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $c = shift @f)) 52 17 69
109 52 ▶ if ( $c =~ /[cxt]/ ) { $mode = $c }
Branch: 7 branches
BranchTrueFalseTotal
if ($c =~ /[cxt]/) { } 16 36 52
elsif ($c eq 'v') { } 1 35 36
elsif ($c eq 'k') { } 1 34 35
elsif ($c eq 'O') { } 1 33 34
elsif ($c eq 'f') { } 16 17 33
elsif ($c eq 'C') { } 0 17 17
elsif ($c eq 'T') { } 1 16 17
110 1 elsif ( $c eq 'v' ) { $verbose = 1 }
111 1 elsif ( $c eq 'k' ) { $keep = 1 }
112 1 elsif ( $c eq 'O' ) { $stdout = 1 }
113 16 ▶ elsif ( $c eq 'f' ) { $file = @f ? join( '', splice @f ) : shift @a }
Branch: 1 branch
BranchTrueFalseTotal
@f ? : 0 16 16
114 0 elsif ( $c eq 'C' ) { $dir = shift @a }
115 1 ▶ elsif ( $c eq 'T' ) { push @lists, @f ? join( '', splice @f ) : shift @a }
Branch: 1 branch
BranchTrueFalseTotal
@f ? : 0 1 1
116 }
117 }
118 7 else { push @mem, $x }
119 }
120 16 ▶ return ( "tar: You must specify one of the '-Acdtrux', '--delete' or '--test-label' options\nTry 'tar --help' or 'tar --usage' for more information.", 0 ) unless $mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $mode 0 16 16
121 16 ▶ return ( "tar: Refusing to read archive contents from terminal (missing -f option?)\ntar: Error is not recoverable: exiting now", 0 ) unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 16 16
122 16 $file = _abs($file);
123 16 for my $l (@lists) { # -T liste | --files-from=liste (- = Eingabe): ein Mitglied je Zeile
124 2 ▶ my $t = $l eq '-' ? $ctx->{stdin} // '' : _L( '_file_text', $dev, _abs($l) );
Branch: 1 branch
BranchTrueFalseTotal
$l eq '-' ? : 1 1 2
Condition50%1/2
$$ctx{"stdin"} // ""
l!l
10
MC/DC0%0/1
$$ctx{"stdin"} // ""
$$ctx{"stdin"}
Truth table50%1/2
A
A= $$ctx{"stdin"}
Aresult
11
00
125 2 ▶ return ( "tar: $l: Cannot open: No such file or directory\ntar: Error is not recoverable: exiting now", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 2 2
126 2 push @mem, grep { length } split /\n/, $t;
127 }
128 16 ▶ if ( $mode eq 'c' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "c") 5 11 16
129 5 ▶ return ( "tar: Cowardly refusing to create an empty archive\nTry 'tar --help' or 'tar --usage' for more information.", 0 ) unless @mem;
Branch: 1 branch
BranchTrueFalseTotal
unless @mem 0 5 5
130 5 my %m;
131 my @o;
132 # Mitglieder heissen wie angegeben (relativ zu -C bzw. dem aktuellen Verzeichnis), ohne fuehrendes /
133 5 ▶ my $base = defined $dir ? _abs($dir) : _cwd() // '/root';
Branch: 1 branch
BranchTrueFalseTotal
defined $dir ? : 0 5 5
Condition50%1/2
_cwd() // "/root"
l!l
05
MC/DC0%0/1
_cwd() // "/root"
_cwd()
Truth table50%1/2
A
A= _cwd()
Aresult
11
00
134 5 for my $arg (@mem) {
135 7 ▶ my $p = $arg =~ m{\A/} ? $arg : ( $base eq '/' ? '' : $base ) . '/' . ( $arg =~ s{\A\./?}{}r );
Branch: 2 branches
BranchTrueFalseTotal
$arg =~ m[\A/] ? : 7 0 7
$base eq '/' ? : 0 0 0
136 7 $p =~ s{(?<=.)/+\z}{};
137 7 ▶ my @f = _entry( $dev, $p ) ? ($p) : _L( '_under', $dev, $p );
Branch: 1 branch
BranchTrueFalseTotal
_entry($dev, $p) ? : 4 3 7
138 7 ▶ return ( "tar: $arg: Cannot stat: No such file or directory\ntar: Exiting with failure status due to previous errors", 0 ) unless @f;
Branch: 1 branch
BranchTrueFalseTotal
unless @f 0 7 7
139 7 ( my $name = $arg ) =~ s{\A/+}{};
140 7 $name =~ s{/+\z}{};
141 7 for my $f (@f) {
142 11 my $rel = $name . substr( $f, length $p );
143 11 $rel =~ s{\A/}{};
144 11 ▶ next if _tar_excluded( $rel, @ex );
Branch: 1 branch
BranchTrueFalseTotal
if _tar_excluded($rel, @ex) 2 9 11
145 9 $m{$rel} = copy_entry( _entry( $dev, $f ), 1 );
146 9 ▶ push @o, $rel if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 9 9
147 }
148 }
149 # Groesse: die Mitglieder plus Kopf (ungepackt gerechnet; ein leeres Archiv zeigt ls nicht als 0)
150 5 my $sum = 10240;
151 5 $sum += _L( '_file_size', $_ ) for values %m;
152 5 _put( $dev, $file, { tar => \%m, owner => 'root', group => 'root', mode => '0644', mtime => _now_text(), content => '', size => $sum } );
153 5 ▶ if ($remove) { # --remove-files: die Quellen nach dem Packen entfernen
Branch: 1 branch
BranchTrueFalseTotal
if ($remove) 1 4 5
154 1 for my $arg (@mem) {
155 2 ▶ my $p = $arg =~ m{\A/} ? $arg : ( $base eq '/' ? '' : $base ) . '/' . ( $arg =~ s{\A\./?}{}r );
Branch: 2 branches
BranchTrueFalseTotal
$arg =~ m[\A/] ? : 2 0 2
$base eq '/' ? : 0 0 0
156 2 _L( '_rm', $dev, [ '-rf', $p =~ s{(?<=.)/+\z}{}r ] );
157 }
158 }
159 5 ▶ return ( join( "\n", ( grep { m{\A/} } @mem ) ? "tar: Removing leading `/' from member names" : (), @o ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
grep({m[\A/];} @mem) ? : 5 0 5
160 }
161 11 my $ar = _entry( $dev, $file );
162 11 ▶ return ( "tar: $file: Cannot open: No such file or directory\ntar: Error is not recoverable: exiting now", 0 ) unless $ar;
Branch: 1 branch
BranchTrueFalseTotal
unless $ar 0 11 11
163 11 my $members = $ar->{tar};
164 11 ▶ return ( "tar: This does not look like a tar archive\ntar: Exiting with failure status due to previous errors", 0 ) unless ref $members eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $members eq "HASH" 0 11 11
165 11 my @names = sort keys %$members;
166 11 ▶ if ( $ar->{corrupt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$ar{"corrupt"}) 1 10 11
167 1 my @half = @names[ 0 .. int( $#names / 2 ) ];
168 1 ▶ return ( join( "\n", ( $mode eq 't' ? @half : () ), 'gzip: stdin: unexpected end of file', 'tar: Unexpected EOF in archive',
Branch: 1 branch
BranchTrueFalseTotal
$mode eq 't' ? : 1 0 1
169 'tar: Error is not recoverable: exiting now' ), 0 );
170 }
171 10 my @want = map { s{\A/+}{}r } @mem;
172 10 my @sel;
173 my %hit;
174 10 for my $n (@names) {
175 18 ▶ next if _tar_excluded( $n, @ex );
Branch: 1 branch
BranchTrueFalseTotal
if _tar_excluded($n, @ex) 0 18 18
176 18 ▶ if (@want) {
Branch: 1 branch
BranchTrueFalseTotal
if (@want) 8 10 18
177 8 ▶ my ($w) = grep { my $x = $_ =~ s{/+\z}{}r; $n eq $x || index( $n, "$x/" ) == 0 } @want;
Condition66%2/3
$n eq $x || index($n, "$x/") == 0
l!l&&r!l&&!r
305
MC/DC50%1/2
$n eq $x || index($n, "$x/") == 0
$n eq $x index($n, "$x/") == 0
Truth table66%2/3
A || B
A= $n eq $xB= index($n, "$x/") == 0
ABresult
1X1
011
000
178 8 ▶ next unless defined $w;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $w 5 3 8
179 3 $hit{$w} = 1;
180 }
181 13 push @sel, $n;
182 }
183 10 my @miss = grep { !$hit{$_} } @want;
184 10 ▶ my $err = @miss ? join( "\n", ( map {"tar: $_: Not found in archive"} @miss ), 'tar: Exiting with failure status due to previous errors' ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@miss ? : 1 9 10
185 10 ▶ if ( $mode eq 't' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq "t") 4 6 10
186 4 ▶ my @l = $verbose ? map { my $e = $members->{$_}; sprintf '%s %s/%s %8d 2026-%s %s', _L( '_mode_text', oct( $e->{mode} // '0644' ) ), $e->{owner} // 'root', $e->{group} // 'root',
Branch: 1 branch
BranchTrueFalseTotal
$verbose ? : 1 3 4
187 2 ▶ _L( '_file_size', $e ), _date( $e->{mtime} ), $_ } @sel : @sel;
Condition50%3/6
$$e{"mode"} // "0644"
l!l
20
$$e{"owner"} // "root"
l!l
20
$$e{"group"} // "root"
l!l
20
MC/DC0%0/1
$$e{"mode"} // "0644"
$$e{"mode"}
MC/DC0%0/1
$$e{"owner"} // "root"
$$e{"owner"}
MC/DC0%0/1
$$e{"group"} // "root"
$$e{"group"}
Truth table50%1/2
A
A= $$e{"mode"}
Aresult
11
00
Truth table50%1/2
A
A= $$e{"owner"}
Aresult
11
00
Truth table50%1/2
A
A= $$e{"group"}
Aresult
11
00
188 4 ▶ return ( join( "\n", @l, defined $err ? $err : () ), defined $err ? 0 : 1 );
Branch: 2 branches
BranchTrueFalseTotal
defined $err ? : 0 4 4
defined $err ? : 0 4 4
189 }
190 6 ▶ if ($stdout) { return ( join( '', map { $members->{$_}{content} // '' } @sel ) =~ s/\n\z//r . ( defined $err ? "\n$err" : '' ), defined $err ? 0 : 1 ) }
Branch: 3 branches
BranchTrueFalseTotal
if ($stdout) 1 5 6
defined $err ? : 0 1 1
defined $err ? : 0 1 1
Condition50%1/2
$$members{$_}{"content"} // ""
l!l
10
MC/DC0%0/1
$$members{$_}{"content"} // ""
$$members{$_}{"content"}
Truth table50%1/2
A
A= $$members{$_}{"content"}
Aresult
11
00
191 5 ▶ my $base = defined $dir ? _abs($dir) : _cwd() // '/root';
Branch: 1 branch
BranchTrueFalseTotal
defined $dir ? : 3 2 5
Condition100%2/2
_cwd() // "/root"
l!l
11
MC/DC100%1/1
_cwd() // "/root"
_cwd()
Truth table100%2/2
A
A= _cwd()
Aresult
11
00
192 5 ▶ return ( "tar: $base: Cannot open: No such file or directory\ntar: Error is not recoverable: exiting now", 0 ) unless _L( '_is_dir', $dev, $base ) || $base =~ m{\A/(?:tmp|root|srv|var|etc|opt|home|restore|mnt)\b};
Branch: 1 branch
BranchTrueFalseTotal
unless _L("_is_dir", $dev, $base) or $base =~ m[\A/(?:tmp|root|srv|var|etc|opt|home|restore|mnt)\b] 0 5 5
Condition33%1/3
_L("_is_dir", $dev, $base) or $base =~ m[\A/(?:tmp|root|srv|var|etc|opt|home|restore|mnt)\b]
l!l&&r!l&&!r
500
MC/DC0%0/2
_L("_is_dir", $dev, $base) or $base =~ m[\A/(?:tmp|root|srv|var|etc|opt|home|restore|mnt)\b]
_L("_is_dir", $dev, $base) $base =~ m[\A/(?:tmp|root|srv|var|etc|opt|home|restore|mnt)\b]
Truth table33%1/3
A or B
A= _L("_is_dir", $dev, $base)B= $base =~ m[\A/(?:tmp|root|srv|var|etc|opt|home|restore|mnt)\b]
ABresult
1X1
011
000
193 5 my @o;
194 5 for my $n (@sel) {
195 6 my @seg = split m{/}, $n;
196 6 ▶ next if $strip && @seg <= $strip;
Branch: 1 branch
BranchTrueFalseTotal
if $strip and @seg <= $strip 0 6 6
Condition33%1/3
$strip and @seg <= $strip
!ll&&!rl&&r
600
MC/DC0%0/2
$strip and @seg <= $strip
$strip @seg <= $strip
Truth table33%1/3
A and B
A= $stripB= @seg <= $strip
ABresult
0X0
100
111
197 6 ▶ my $rel = join '/', @seg[ ( $strip // 0 ) .. $#seg ];
Condition50%1/2
$strip // 0
l!l
06
MC/DC0%0/1
$strip // 0
$strip
Truth table50%1/2
A
A= $strip
Aresult
11
00
198 6 ▶ my $to = ( $base eq '/' ? '' : $base ) . "/$rel";
Branch: 1 branch
BranchTrueFalseTotal
$base eq '/' ? : 5 1 6
199 6 ▶ if ( $keep && _entry( $dev, $to ) ) { push @o, "tar: $rel: Cannot open: File exists"; $err //= 'tar: Exiting with failure status due to previous errors'; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($keep and _entry($dev, $to)) 2 4 6
Condition80%4/5
$keep and _entry($dev, $to)
!ll&&!rl&&r
402
$err //= "tar: Exiting with failure status due to previous errors"
l!l
11
MC/DC50%1/2
$keep and _entry($dev, $to)
$keep _entry($dev, $to)
MC/DC100%1/1
$err //= "tar: Exiting with failure status due to previous errors"
$err
Truth table66%2/3
A and B
A= $keepB= _entry($dev, $to)
ABresult
0X0
100
111
Truth table100%2/2
A
A= $err
Aresult
11
00
200 4 _put( $dev, $to, copy_entry( $members->{$n}, 1 ) );
201 4 ▶ $dev->{dirs}{$_} //= {} for grep { !_L( '_is_dir', $dev, $_ ) } _parents($to);
Condition0%0/2
$$dev{"dirs"}{$_} //= {}
l!l
00
MC/DC0%0/1
$$dev{"dirs"}{$_} //= {}
$$dev{"dirs"}{$_}
Truth table0%0/2
A
A= $$dev{"dirs"}{$_}
Aresult
11
00
202 4 ▶ push @o, $n if $verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose 0 4 4
203 }
204 5 ▶ return ( join( "\n", @o, defined $err ? $err : () ), defined $err ? 0 : 1 );
Branch: 2 branches
BranchTrueFalseTotal
defined $err ? : 2 3 5
defined $err ? : 2 3 5
205 }
206  
207 4 ▶sub _parents { my ($p) = @_; my @s = split m{/}, $p; return map { join '/', @s[ 0 .. $_ ] } 1 .. $#s - 1 }
Subroutine _parents: called CC=1 SCAR=0.0
208  
209 2 ▶sub _date {
Subroutine _date: called CC=4 SCAR=15.6
210 2 my ($m) = @_;
211 2 my %mon = ( Jan => '01', Feb => '02', Mar => '03', Apr => '04', May => '05', Jun => '06', Jul => '07', Aug => '08', Sep => '09', Oct => '10', Nov => '11', Dec => '12' );
212 2 ▶ return '10-20 12:00' unless defined $m && $m =~ /\A(\w{3})\s+(\d+)\s+(\d+:\d+)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $m and $m =~ /\A(\w{3})\s+(\d+)\s+(\d+:\d+)\z/ 0 2 2
Condition33%1/3
defined $m and $m =~ /\A(\w{3})\s+(\d+)\s+(\d+:\d+)\z/
!ll&&!rl&&r
002
MC/DC0%0/2
defined $m and $m =~ /\A(\w{3})\s+(\d+)\s+(\d+:\d+)\z/
defined $m $m =~ /\A(\w{3})\s+(\d+)\s+(\d+:\d+)\z/
Truth table33%1/3
A and B
A= defined $mB= $m =~ /\A(\w{3})\s+(\d+)\s+(\d+:\d+)\z/
ABresult
0X0
100
111
213 2 ▶ return sprintf '%s-%02d %s', $mon{$1} // '10', $2, $3;
Condition50%1/2
$mon{$1} // 10
l!l
20
MC/DC0%0/1
$mon{$1} // 10
$mon{$1}
Truth table50%1/2
A
A= $mon{$1}
Aresult
11
00
214 }
215  
216  
217 1 ▶sub gzip {
Subroutine gzip: called CC=6 SCAR=19.6
Pod documented
218 1 my ( $dev, $av ) = @_;
219 1 my ($f) = grep { !/\A-/ } @$av;
220 1 ▶ return ( '', 0 ) unless grep { $_ eq '-t' || $_ eq '--test' } @$av; # nur Pruefen ist nachgebildet
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "-t" or $_ eq "--test";} @$av 0 1 1
Condition66%2/3
$_ eq '-t' || $_ eq '--test'
l!l&&r!l&&!r
101
MC/DC50%1/2
$_ eq '-t' || $_ eq '--test'
$_ eq '-t' $_ eq '--test'
Truth table66%2/3
A || B
A= $_ eq '-t'B= $_ eq '--test'
ABresult
1X1
011
000
221 1 ▶ my $e = _entry( $dev, _abs( $f // '' ) ) or return ( "gzip: $f: No such file or directory", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $e = _entry($dev, _abs($f // "")) or return "gzip: ${f}: No such file or directory", 0 1 0 1
Condition50%1/2
$f // ""
l!l
10
MC/DC0%0/1
$f // ""
$f
Truth table50%1/2
A
A= $f
Aresult
11
00
222 1 ▶ return ( "gzip: $f: unexpected end of file", 0 ) if $e->{corrupt};
Branch: 1 branch
BranchTrueFalseTotal
if $$e{"corrupt"} 1 0 1
223 0 return ( '', 1 );
224 }
225  
226 # --- sha256sum -----------------------------------------------------------------------
227  
228 5 ▶sub _sha {
Subroutine _sha: called CC=2 SCAR=6.9
229 5 my ($e) = @_;
230 5 ▶ return $e->{sha256} if defined $e->{sha256};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$e{"sha256"} 2 3 5
231 3 return Digest::SHA::sha256_hex( _L( '_digest_bytes', $e, $e->{content} ) ); # ohne Inhalt: Daten des Eintrags
232 }
233  
234  
235 2 ▶sub sha256sum {
Subroutine sha256sum: called CC=16 SCAR=29.8
Pod documented
236 2 my ( $dev, $av ) = @_;
237 2 my @a = @$av;
238 2 ▶ my $check = grep { $_ eq '-c' || $_ eq '--check' } @a;
Condition66%2/3
$_ eq '-c' || $_ eq '--check'
l!l&&r!l&&!r
104
MC/DC50%1/2
$_ eq '-c' || $_ eq '--check'
$_ eq '-c' $_ eq '--check'
Truth table66%2/3
A || B
A= $_ eq '-c'B= $_ eq '--check'
ABresult
1X1
011
000
239 2 my $quiet = grep { $_ eq '--quiet' } @a;
240 2 my @f = grep { !/\A-/ } @a;
241 2 my ( @l, $ok, $bad );
242 2 $ok = 1;
243 2 ▶ if ($check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check) 1 1 2
244 1 for my $lf (@f) {
245 1 my $t = _L( '_file_text', $dev, _abs($lf) );
246 1 ▶ return ( "sha256sum: $lf: No such file or directory", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1 1
247 1 for my $line ( split /\n/, $t ) {
248 2 ▶ my ( $h, $p ) = $line =~ /\A([0-9a-f]{64})\s+\*?(.+?)\s*\z/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $line =~ /\A([0-9a-f]{64})\s+\*?(.+?)\s*\z/ or next 2 0 2
249 2 ▶ my $path = $p =~ m{\A/} ? $p : do { ( my $d = _abs($lf) ) =~ s{/[^/]*\z}{}; _cwd() ? _abs($p) : "$d/$p" };
Branch: 2 branches
BranchTrueFalseTotal
$p =~ m[\A/] ? : 0 2 2
_cwd() ? : 2 0 2
250 2 my $e = _entry( $dev, $path );
251 0 ▶ if ( !$e ) { push @l, "sha256sum: $p: No such file or directory", "$p: FAILED open or read"; $ok = 0 }
Branch: 2 branches
BranchTrueFalseTotal
if (not $e) { } 0 2 2
elsif (_sha($e) eq $h) { } 1 1 2
252 1 ▶ elsif ( _sha($e) eq $h ) { push @l, "$p: OK" unless $quiet }
Branch: 1 branch
BranchTrueFalseTotal
unless $quiet 1 0 1
253 1 else { push @l, "$p: FAILED"; $bad++; $ok = 0 }
254 }
255 }
256 1 ▶ push @l, "sha256sum: WARNING: $bad computed checksum" . ( $bad == 1 ? '' : 's' ) . ' did NOT match' if $bad;
Branch: 2 branches
BranchTrueFalseTotal
if $bad 1 0 1
$bad == 1 ? : 1 0 1
257 1 return ( join( "\n", @l ), $ok );
258 }
259 1 for my $p (@f) {
260 3 my $e = _entry( $dev, _abs($p) );
261 0 ▶ if ( !$e ) { push @l, "sha256sum: $p: No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($e) 0 3 3
262 3 push @l, _sha($e) . " $p";
263 }
264 1 return ( join( "\n", @l ), $ok );
265 }
266  
267 # --- rsync ---------------------------------------------------------------------------
268  
269 12 ▶sub _loc {
Subroutine _loc: called CC=7 SCAR=20.5
270 12 my ( $dev, $ctx, $spec ) = @_;
271 12 ▶ if ( $spec =~ /\A(?:([\w.-]+)@)?([\w.-]+):(.*)\z/ && $spec !~ m{\A/} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec =~ /\A(?:([\w.-]+)@)?([\w.-]+):(.*)\z/ and not $spec =~ m[\A/]) 1 11 12
Condition66%2/3
$spec =~ /\A(?:([\w.-]+)@)?([\w.-]+):(.*)\z/ and not $spec =~ m[\A/]
!ll&&!rl&&r
1101
MC/DC50%1/2
$spec =~ /\A(?:([\w.-]+)@)?([\w.-]+):(.*)\z/ and not $spec =~ m[\A/]
$spec =~ /\A(?:([\w.-]+)@)?([\w.-]+):(.*)\z/ not $spec =~ m[\A/]
Truth table66%2/3
A and not(B)
A= $spec =~ /\A(?:([\w.-]+)@)?([\w.-]+):(.*)\z/B= not $spec =~ m[\A/]
ABresult
0X0
100
111
272 1 my ( $h, $p ) = ( $2, $3 );
273 1 ▶ my $d = ( $ctx->{state} || {} )->{$h};
Condition50%1/2
$$ctx{'state'} || {}
l!l
10
MC/DC0%0/1
$$ctx{'state'} || {}
$$ctx{'state'}
Truth table50%1/2
A
A= $$ctx{'state'}
Aresult
11
00
274 1 ▶ return ( undef, undef, "ssh: Could not resolve hostname $h: Name or service not known" ) unless ref $d eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $d eq "HASH" 0 1 1
275 1 ▶ return ( $d, length $p ? ( $p =~ m{\A/} ? $p : "/root/$p" ) : '/root' );
Branch: 2 branches
BranchTrueFalseTotal
length $p ? : 1 0 1
$p =~ m[\A/] ? : 1 0 1
276 }
277 11 return ( $dev, _abs($spec) );
278 }
279  
280 19 ▶sub _ex_match {
Subroutine _ex_match: called CC=4 SCAR=13.9
281 19 my ( $rel, $pats ) = @_;
282 19 for my $p (@$pats) {
283 4 my $q = $p;
284 4 my $anch = $q =~ s{\A/}{};
285 4 $q =~ s{/+\z}{};
286 4 ( my $re = quotemeta $q ) =~ s/\\\*\\\*/.*/g;
287 4 $re =~ s/\\\*/[^\/]*/g;
288 4 $re =~ s/\\\?/[^\/]/g;
289 4 ▶ return 1 if $anch ? $rel =~ /\A$re(?:\/|\z)/ : $rel =~ /(?:\A|\/)$re(?:\/|\z)/;
Branch: 2 branches
BranchTrueFalseTotal
if $anch ? $rel =~ m[\A$re(?:/|\z)] : $rel =~ m[(?:\A|/)$re(?:/|\z)] 1 3 4
$anch ? : 0 4 4
290 }
291 18 return 0;
292 }
293  
294  
295 6 ▶sub rsync {
Subroutine rsync: called CC=63 SCAR=50.0
Pod documented
296 6 my ( $dev, $av, $ctx ) = @_;
297 6 my @a = @$av;
298 6 my ( %o, @ex, @args );
299 6 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 22 6 28
300 22 my $x = shift @a;
301 0 ▶ if ( $x =~ /\A--exclude=(.+)\z/ ) { push @ex, $1 }
Branch: 10 branches
BranchTrueFalseTotal
if ($x =~ /\A--exclude=(.+)\z/) { } 0 22 22
elsif ($x eq '--exclude') { } 1 21 22
elsif ($x eq '--delete' or $x =~ /\A--delete-(?:after|before|during|delay)\z/) { } 3 18 21
elsif ($x eq '--delete-excluded') { } 0 18 18
elsif ($x eq '--dry-run') { } 0 18 18
elsif ($x eq '--archive') { } 0 18 18
elsif ($x eq '--recursive') { } 0 18 18
elsif ($x eq '-e' or $x eq '--rsh') { } 0 18 18
elsif ($x =~ /\A--/) { } 0 18 18
elsif ($x =~ /\A-([a-zA-Z]+)\z/) { } 6 12 18
302 1 elsif ( $x eq '--exclude' ) { push @ex, shift @a }
303 3 ▶ elsif ( $x eq '--delete' || $x =~ /\A--delete-(?:after|before|during|delay)\z/ ) { $o{delete} = 1 }
Condition66%2/3
$x eq "--delete" or $x =~ /\A--delete-(?:after|before|during|delay)\z/
l!l&&r!l&&!r
3018
MC/DC50%1/2
$x eq "--delete" or $x =~ /\A--delete-(?:after|before|during|delay)\z/
$x eq "--delete" $x =~ /\A--delete-(?:after|before|during|delay)\z/
Truth table66%2/3
A or B
A= $x eq "--delete"B= $x =~ /\A--delete-(?:after|before|during|delay)\z/
ABresult
1X1
011
000
304 0 elsif ( $x eq '--delete-excluded' ) { $o{delete} = $o{delexcl} = 1 }
305 0 elsif ( $x eq '--dry-run' ) { $o{n} = 1 }
306 0 elsif ( $x eq '--archive' ) { $o{a} = 1 }
307 0 elsif ( $x eq '--recursive' ) { $o{r} = 1 }
308 0 ▶ elsif ( $x eq '-e' || $x eq '--rsh' ) { shift @a }
Condition33%1/3
$x eq "-e" or $x eq "--rsh"
l!l&&r!l&&!r
0018
MC/DC0%0/2
$x eq "-e" or $x eq "--rsh"
$x eq "-e" $x eq "--rsh"
Truth table33%1/3
A or B
A= $x eq "-e"B= $x eq "--rsh"
ABresult
1X1
011
000
309 elsif ( $x =~ /\A--/ ) { }
310 6 elsif ( $x =~ /\A-([a-zA-Z]+)\z/ ) { $o{$_} = 1 for split //, $1 }
311 12 else { push @args, $x }
312 }
313 6 ▶ return ( "rsync: [Receiver] error: need at least a source and a destination\nrsync error: syntax or usage error (code 1) at main.c(1678) [Receiver=3.2.7]", 0 ) unless @args >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @args >= 2 0 6 6
314 6 my $dst_spec = pop @args;
315 6 ▶ my $rec = $o{a} || $o{r};
Condition66%2/3
$o{'a'} || $o{'r'}
l!l&&r!l&&!r
510
MC/DC0%0/2
$o{'a'} || $o{'r'}
$o{'a'} $o{'r'}
Truth table66%2/3
A || B
A= $o{'a'}B= $o{'r'}
ABresult
1X1
011
000
316 6 ▶ my $keep = $o{a} || ( $o{p} && $o{o} && $o{g} && $o{t} );
Condition41%5/12
$o{'a'} || $o{'p'} && $o{'o'} && $o{'g'} && $o{'t'}
l!l&&r!l&&!r
501
$o{"p"} and $o{"o"} and $o{"g"} and $o{"t"}
!ll&&!rl&&r
100
$o{"p"} and $o{"o"} and $o{"g"}
!ll&&!rl&&r
100
$o{"p"} and $o{"o"}
!ll&&!rl&&r
100
MC/DC20%1/5
$o{'a'} || $o{'p'} && $o{'o'} && $o{'g'} && $o{'t'}
$o{'a'} $o{"p"} $o{"o"} $o{"g"} $o{"t"}
Truth table33%2/6
A || B and C and D and E
A= $o{'a'}B= $o{"p"}C= $o{"o"}D= $o{"g"}E= $o{"t"}
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
317 6 my ( $dd, $dp, $de ) = _loc( $dev, $ctx, $dst_spec );
318 6 ▶ return ( "$de\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: unexplained error (code 255) at io.c(231) [sender=3.2.7]", 0 ) if $de;
Branch: 1 branch
BranchTrueFalseTotal
if $de 0 6 6
319 6 $dp =~ s{(?<=.)/+\z}{};
320 6 my ( @out, %sent );
321 6 my $err;
322 6 for my $s (@args) {
323 6 my $slash = $s =~ m{/\z};
324 6 my ( $sd, $sp, $se ) = _loc( $dev, $ctx, $s );
325 6 ▶ return ( "$se\nrsync: connection unexpectedly closed (0 bytes received so far) [Receiver]\nrsync error: unexplained error (code 255) at io.c(231) [Receiver=3.2.7]", 0 ) if $se;
Branch: 1 branch
BranchTrueFalseTotal
if $se 0 6 6
326 6 $sp =~ s{(?<=.)/+\z}{};
327 6 my @files;
328 6 ▶ if ( _entry( $sd, $sp ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (_entry($sd, $sp)) { } 1 5 6
elsif (_L('_is_dir', $sd, $sp)) { } 5 0 5
329 1 ( my $b = $sp ) =~ s{.*/}{};
330 1 ▶ my $to = _L( '_is_dir', $dd, $dp ) || $dst_spec =~ m{/\z} || @args > 1 ? "$dp/$b" : $dp;
Branch: 1 branch
BranchTrueFalseTotal
_L('_is_dir', $dd, $dp) || $dst_spec =~ m[/\z] || @args > 1 ? : 1 0 1
Condition33%2/6
_L("_is_dir", $dd, $dp) or $dst_spec =~ m[/\z] or @args > 1
l!l&&r!l&&!r
100
_L("_is_dir", $dd, $dp) or $dst_spec =~ m[/\z]
l!l&&r!l&&!r
100
MC/DC0%0/3
_L("_is_dir", $dd, $dp) or $dst_spec =~ m[/\z] or @args > 1
_L("_is_dir", $dd, $dp) $dst_spec =~ m[/\z] @args > 1
Truth table25%1/4
A or B or C
A= _L("_is_dir", $dd, $dp)B= $dst_spec =~ m[/\z]C= @args > 1
ABCresult
1XX1
01X1
0011
0000
331 1 push @files, [ $sp, $to, $b ];
332 }
333 elsif ( _L( '_is_dir', $sd, $sp ) ) {
334 0 ▶ if ( !$rec ) { push @out, "skipping directory $sp"; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($rec) 0 5 5
335 5 ( my $b = $sp ) =~ s{.*/}{};
336 5 ▶ my $root = $slash ? $dp : ( $dp eq '/' ? '' : $dp ) . "/$b";
Branch: 2 branches
BranchTrueFalseTotal
$slash ? : 4 1 5
$dp eq '/' ? : 0 1 1
337 5 for my $f ( _L( '_under', $sd, $sp ) ) {
338 15 my $rel = substr( $f, length($sp) + 1 );
339 15 ▶ my $xrel = $slash ? $rel : "$b/$rel";
Branch: 1 branch
BranchTrueFalseTotal
$slash ? : 12 3 15
340 15 ▶ next if _ex_match( $xrel, \@ex );
Branch: 1 branch
BranchTrueFalseTotal
if _ex_match($xrel, \@ex) 1 14 15
341 14 push @files, [ $f, "$root/$rel", $xrel ];
342 }
343 5 ▶ $sent{$root} = { map { $_->[1] => 1 } @files } if $o{delete};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"delete"} 3 2 5
344 5 ▶ $sent{$root}{__root} = $slash ? '' : $b if $o{delete};
Branch: 2 branches
BranchTrueFalseTotal
if $o{"delete"} 3 2 5
$slash ? : 3 0 3
345 }
346 else {
347 0 push @out, "rsync: [sender] change_dir \"$sp\" failed: No such file or directory (2)";
348 0 $err = 1;
349 0 next;
350 }
351 6 for my $f (@files) {
352 15 my ( $from, $to, $rel ) = @$f;
353 15 ▶ push @out, $rel if $o{v} || $o{n};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"v"} or $o{"n"} 4 11 15
Condition100%3/3
$o{"v"} or $o{"n"}
l!l&&r!l&&!r
1311
MC/DC100%2/2
$o{"v"} or $o{"n"}
$o{"v"} $o{"n"}
Truth table100%3/3
A or B
A= $o{"v"}B= $o{"n"}
ABresult
1X1
011
000
354 15 ▶ next if $o{n};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"n"} 3 12 15
355 12 my $e = copy_entry( _entry( $sd, $from ), $keep );
356 0 ▶ if ( !$keep && $o{p} ) { $e->{mode} = _entry( $sd, $from )->{mode} if ref _entry( $sd, $from ) eq 'HASH' && defined _entry( $sd, $from )->{mode} }
Branch: 2 branches
BranchTrueFalseTotal
if (not $keep and $o{"p"}) 0 12 12
if ref _entry($sd, $from) eq "HASH" and defined _entry($sd, $from)->{"mode"} 0 0 0
Condition33%2/6
not $keep and $o{"p"}
!ll&&!rl&&r
930
ref _entry($sd, $from) eq "HASH" and defined _entry($sd, $from)->{"mode"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $keep and $o{"p"}
not $keep $o{"p"}
MC/DC0%0/2
ref _entry($sd, $from) eq "HASH" and defined _entry($sd, $from)->{"mode"}
ref _entry($sd, $from) eq "HASH" defined _entry($sd, $from)->{"mode"}
Truth table66%2/3
not(A) and B
A= not $keepB= $o{"p"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref _entry($sd, $from) eq "HASH"B= defined _entry($sd, $from)->{"mode"}
ABresult
0X0
100
111
357 12 _put( $dd, $to, $e );
358 }
359 }
360 6 ▶ if ( $o{delete} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"delete"}) 3 3 6
361 3 for my $root ( sort keys %sent ) {
362 3 my $have = $sent{$root};
363 3 for my $f ( _L( '_under', $dd, $root ) ) {
364 9 ▶ next if $have->{$f};
Branch: 1 branch
BranchTrueFalseTotal
if $$have{$f} 5 4 9
365 4 my $rel = substr( $f, length($root) + 1 );
366 4 ▶ my $xrel = length $have->{__root} ? "$have->{__root}/$rel" : $rel;
Branch: 1 branch
BranchTrueFalseTotal
length $$have{'__root'} ? : 0 4 4
367 4 ▶ next if !$o{delexcl} && _ex_match( $xrel, \@ex );
Branch: 1 branch
BranchTrueFalseTotal
if not $o{"delexcl"} and _ex_match($xrel, \@ex) 0 4 4
Condition33%1/3
not $o{"delexcl"} and _ex_match($xrel, \@ex)
!ll&&!rl&&r
040
MC/DC0%0/2
not $o{"delexcl"} and _ex_match($xrel, \@ex)
not $o{"delexcl"} _ex_match($xrel, \@ex)
Truth table33%1/3
not(A) and B
A= not $o{"delexcl"}B= _ex_match($xrel, \@ex)
ABresult
0X0
100
111
368 4 ▶ push @out, "deleting $rel" if $o{v} || $o{n};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"v"} or $o{"n"} 1 3 4
Condition66%2/3
$o{"v"} or $o{"n"}
l!l&&r!l&&!r
013
MC/DC50%1/2
$o{"v"} or $o{"n"}
$o{"v"} $o{"n"}
Truth table66%2/3
A or B
A= $o{"v"}B= $o{"n"}
ABresult
1X1
011
000
369 4 ▶ delete $dd->{files}{$f} unless $o{n};
Branch: 1 branch
BranchTrueFalseTotal
unless $o{"n"} 3 1 4
370 }
371 }
372 }
373 6 ▶ unshift @out, 'sending incremental file list' if $o{v} || $o{n};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"v"} or $o{"n"} 2 4 6
Condition100%3/3
$o{"v"} or $o{"n"}
l!l&&r!l&&!r
114
MC/DC100%2/2
$o{"v"} or $o{"n"}
$o{"v"} $o{"n"}
Truth table100%3/3
A or B
A= $o{"v"}B= $o{"n"}
ABresult
1X1
011
000
374 6 ▶ push @out, '', 'sent 1,024 bytes received 64 bytes 2,176.00 bytes/sec', 'total size is 4,096 speedup is 3.76' . ( $o{n} ? ' (DRY RUN)' : '' ) if $o{v} || $o{n};
Branch: 2 branches
BranchTrueFalseTotal
if $o{"v"} or $o{"n"} 2 4 6
$o{'n'} ? : 1 1 2
Condition100%3/3
$o{"v"} or $o{"n"}
l!l&&r!l&&!r
114
MC/DC100%2/2
$o{"v"} or $o{"n"}
$o{"v"} $o{"n"}
Truth table100%3/3
A or B
A= $o{"v"}B= $o{"n"}
ABresult
1X1
011
000
375 6 ▶ push @out, 'rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1338) [sender=3.2.7]' if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 6 6
376 6 ▶ return ( join( "\n", @out ), $err ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 6 6
377 }
378  
379 # --- restic --------------------------------------------------------------------------
380  
381 23 ▶sub _repo {
Subroutine _repo: called CC=6 SCAR=18.3
382 23 my ( $dev, $ctx, $spec ) = @_;
383 23 my ( $d, $p );
384 23 ▶ if ( $spec =~ /\Asftp:(?:[\w.-]+@)?([\w.-]+):(.+)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec =~ /\Asftp:(?:[\w.-]+@)?([\w.-]+):(.+)\z/) { } 21 2 23
385 21 ▶ $d = ( $ctx->{state} || {} )->{$1};
Condition50%1/2
$$ctx{'state'} || {}
l!l
210
MC/DC0%0/1
$$ctx{'state'} || {}
$$ctx{'state'}
Truth table50%1/2
A
A= $$ctx{'state'}
Aresult
11
00
386 21 ▶ return ( undef, "Fatal: unable to open repository at $spec: unable to start the sftp session, error: EOF" ) unless ref $d eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $d eq "HASH" 0 21 21
387 21 $p = $2;
388 }
389 2 else { ( $d, $p ) = ( $dev, _abs($spec) ) }
390 23 $p =~ s{(?<=.)/+\z}{};
391 23 ▶ my $r = ( $d->{restic_repos} || {} )->{$p};
Condition50%1/2
$$d{'restic_repos'} || {}
l!l
230
MC/DC0%0/1
$$d{'restic_repos'} || {}
$$d{'restic_repos'}
Truth table50%1/2
A
A= $$d{'restic_repos'}
Aresult
11
00
392 23 ▶ return ( undef, "Fatal: repository does not exist: unable to open config file: stat $p/config: no such file or directory\nIs there a repository at the following location?\n$spec" ) unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 23 23
393 23 return ($r);
394 }
395  
396 3 ▶sub _ts { my ($t) = @_; my @f = $t =~ /(\d+)/g; return Time::Local::timegm( $f[5] // 0, $f[4] // 0, $f[3] // 0, $f[2], $f[1] - 1, $f[0] ) }
Subroutine _ts: called CC=4 SCAR=15.2
Condition50%3/6
$f[5] // 0
l!l
30
$f[4] // 0
l!l
30
$f[3] // 0
l!l
30
MC/DC0%0/1
$f[5] // 0
$f[5]
MC/DC0%0/1
$f[4] // 0
$f[4]
MC/DC0%0/1
$f[3] // 0
$f[3]
Truth table50%1/2
A
A= $f[5]
Aresult
11
00
Truth table50%1/2
A
A= $f[4]
Aresult
11
00
Truth table50%1/2
A
A= $f[3]
Aresult
11
00
397  
398 # Filter --host/--path/--tag; a filter not given selects all
399 17 ▶sub _sel {
Subroutine _sel: called CC=10 SCAR=26.4
400 17 my ( $snaps, %f ) = @_;
401 17 ▶ $f{$_} ||= [] for qw( host path tag );
Condition50%1/2
$f{$_} ||= []
l!l
510
MC/DC0%0/1
$f{$_} ||= []
$f{$_}
Truth table50%1/2
A
A= $f{$_}
Aresult
11
00
402 return grep {
403 17 my $s = $_;
404 96 ▶ ( !@{ $f{host} } || grep { $_ eq $s->{host} } @{ $f{host} } )
Condition66%2/3
not @{$f{"path"};} or grep {my $p = $_; grep {$_ eq $p;} @{$$s{"paths"} or [];};} @{$f{"path"};}
l!l&&r!l&&!r
8606
MC/DC50%1/2
not @{$f{"path"};} or grep {my $p = $_; grep {$_ eq $p;} @{$$s{"paths"} or [];};} @{$f{"path"};}
not @{$f{"path"};} grep {my $p = $_; grep {$_ eq $p;} @{$$s{"paths"} or [];};} @{$f{"path"};}
Truth table66%2/3
not(A) or B
A= not @{$f{"path"};}B= grep {my $p = $_; grep {$_ eq $p;} @{$$s{"paths"} or [];};} @{$f{"path"};}
ABresult
1X1
011
000
405 0 ▶ && ( !@{ $f{path} } || grep { my $p = $_; grep { $_ eq $p } @{ $s->{paths} || [] } } @{ $f{path} } )
Condition40%2/5
$$s{'paths'} || []
l!l
06
not @{$f{"tag"};} or grep {my $t = $_; grep {$_ eq $t;} @{$$s{"tags"} or [];};} @{$f{"tag"};}
l!l&&r!l&&!r
8600
MC/DC0%0/1
$$s{'paths'} || []
$$s{'paths'}
MC/DC0%0/2
not @{$f{"tag"};} or grep {my $t = $_; grep {$_ eq $t;} @{$$s{"tags"} or [];};} @{$f{"tag"};}
not @{$f{"tag"};} grep {my $t = $_; grep {$_ eq $t;} @{$$s{"tags"} or [];};} @{$f{"tag"};}
Truth table50%1/2
A
A= $$s{'paths'}
Aresult
11
00
Truth table33%1/3
not(A) or B
A= not @{$f{"tag"};}B= grep {my $t = $_; grep {$_ eq $t;} @{$$s{"tags"} or [];};} @{$f{"tag"};}
ABresult
1X1
011
000
406 0 ▶ && ( !@{ $f{tag} } || grep { my $t = $_; grep { $_ eq $t } @{ $s->{tags} || [] } } @{ $f{tag} } )
Condition72%8/11
(!@{$f{'host'};} || grep({$_ eq $$s{'host'};} @{$f{'host'};})) && (!@{$f{'path'};} || grep({my $p = $_; grep {$_ eq $p;} @{$$s{'paths'} or [];};} @{$f{'path'};})) && (!@{$f{'tag'};} || grep({my $t = $_; grep {$_ eq $t;} @{$$s{'tags'} or [];};} @{$f{'tag'};}))
!ll&&!rl&&r
10086
!@{$f{"host"};} || grep({$_ eq $$s{"host"};} @{$f{"host"};}) and !@{$f{"path"};} || grep({my $p = $_; grep {$_ eq $p;} @{$$s{"paths"} or [];};} @{$f{"path"};})
!ll&&!rl&&r
4686
not @{$f{"host"};} or grep {$_ eq $$s{"host"};} @{$f{"host"};}
l!l&&r!l&&!r
72204
$$s{'tags'} || []
l!l
00
MC/DC0%0/4
(!@{$f{'host'};} || grep({$_ eq $$s{'host'};} @{$f{'host'};})) && (!@{$f{'path'};} || grep({my $p = $_; grep {$_ eq $p;} @{$$s{'paths'} or [];};} @{$f{'path'};})) && (!@{$f{'tag'};} || grep({my $t = $_; grep {$_ eq $t;} @{$$s{'tags'} or [];};} @{$f{'tag'};}))
not @{$f{"host"};} grep {$_ eq $$s{"host"};} @{$f{"host"};} !@{$f{"path"};} || grep({my $p = $_; grep {$_ eq $p;} @{$$s{"paths"} or [];};} @{$f{"path"};}) (!@{$f{'tag'};} || grep({my $t = $_; grep {$_ eq $t;} @{$$s{'tags'} or [];};} @{$f{'tag'};}))
MC/DC0%0/1
$$s{'tags'} || []
$$s{'tags'}
Truth table14%1/7
not(A) or B and C && D
A= not @{$f{"host"};}B= grep {$_ eq $$s{"host"};} @{$f{"host"};}C= !@{$f{"path"};} || grep({my $p = $_; grep {$_ eq $p;} @{$$s{"paths"} or [];};} @{$f{"path"};})D= (!@{$f{'tag'};} || grep({my $t = $_; grep {$_ eq $t;} @{$$s{'tags'} or [];};} @{$f{'tag'};}))
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
Truth table0%0/2
A
A= $$s{'tags'}
Aresult
11
00
407 } @$snaps;
408 }
409  
410 10 ▶sub _find_snap {
Subroutine _find_snap: called CC=5 SCAR=16.4
411 10 my ( $r, $id, %f ) = @_;
412 10 ▶ my @s = sort { $a->{time} cmp $b->{time} } _sel( $r->{snapshots} || [], %f );
Condition50%1/2
$$r{'snapshots'} || []
l!l
100
MC/DC0%0/1
$$r{'snapshots'} || []
$$r{'snapshots'}
Truth table50%1/2
A
A= $$r{'snapshots'}
Aresult
11
00
413 10 ▶ return $s[-1] if $id eq 'latest';
Branch: 1 branch
BranchTrueFalseTotal
if $id eq "latest" 4 6 10
414 6 ▶ my @m = grep { index( $_->{id}, $id ) == 0 } @{ $r->{snapshots} || [] };
Condition50%1/2
$$r{'snapshots'} || []
l!l
60
MC/DC0%0/1
$$r{'snapshots'} || []
$$r{'snapshots'}
Truth table50%1/2
A
A= $$r{'snapshots'}
Aresult
11
00
415 6 ▶ return @m == 1 ? $m[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@m == 1 ? : 6 0 6
416 }
417  
418 34 ▶sub _snap_line {
Subroutine _snap_line: called CC=4 SCAR=14.0
419 34 my ($s) = @_;
420 34 ▶ my @p = @{ $s->{paths} || [] };
Condition100%2/2
$$s{'paths'} || []
l!l
2212
MC/DC100%1/1
$$s{'paths'} || []
$$s{'paths'}
Truth table100%2/2
A
A= $$s{'paths'}
Aresult
11
00
421 34 ▶ my @l = sprintf( '%-9s %-20s %-11s %-11s %s', substr( $s->{id}, 0, 8 ), $s->{time}, $s->{host}, join( ',', @{ $s->{tags} || [] } ), shift(@p) // '' );
Condition75%3/4
$$s{'tags'} || []
l!l
340
shift @p // ""
l!l
2212
MC/DC0%0/1
$$s{'tags'} || []
$$s{'tags'}
MC/DC100%1/1
shift @p // ""
shift @p
Truth table50%1/2
A
A= $$s{'tags'}
Aresult
11
00
Truth table100%2/2
A
A= shift @p
Aresult
11
00
422 0 push @l, map { ( ' ' x 54 ) . $_ } @p;
423 34 return @l;
424 }
425  
426 # Aufbewahrung wie restic (internal/restic/snapshot_policy.go): neueste zuerst
427 6 ▶sub _policy {
Subroutine _policy: called CC=9 SCAR=22.3
428 6 my ( $list, $keep ) = @_;
429 6 my @s = sort { $b->{time} cmp $a->{time} } @$list;
430 my %fn = (
431 4 ▶ last => sub { $_[0]{id} },
Subroutine __ANON__: called CC=1 SCAR=0.0
432 0 ▶ hourly => sub { POSIX::strftime( '%Y%m%d%H', gmtime _ts( $_[0]{time} ) ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
433 3 ▶ daily => sub { POSIX::strftime( '%Y%m%d', gmtime _ts( $_[0]{time} ) ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
434 0 ▶ weekly => sub { POSIX::strftime( '%G%V', gmtime _ts( $_[0]{time} ) ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
435 0 ▶ monthly => sub { POSIX::strftime( '%Y%m', gmtime _ts( $_[0]{time} ) ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
436 0 ▶ yearly => sub { POSIX::strftime( '%Y', gmtime _ts( $_[0]{time} ) ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
437 5 );
438 5 my %cnt = map { $_ => $keep->{$_} } grep { defined $keep->{$_} } keys %fn;
439 5 my %last = ();
440 5 my ( @k, @r );
441 5 ▶ return ( \@s, [] ) unless %cnt;
Branch: 1 branch
BranchTrueFalseTotal
unless %cnt 0 5 5
442 5 for my $sn (@s) {
443 17 my $kp;
444 17 for my $rule ( sort keys %cnt ) {
445 17 ▶ next unless $cnt{$rule};
Branch: 1 branch
BranchTrueFalseTotal
unless $cnt{$rule} 10 7 17
446 7 my $v = $fn{$rule}->($sn);
447 7 ▶ next if defined $last{$rule} && $last{$rule} eq $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $last{$rule} and $last{$rule} eq $v 1 6 7
Condition100%3/3
defined $last{$rule} and $last{$rule} eq $v
!ll&&!rl&&r
511
MC/DC100%2/2
defined $last{$rule} and $last{$rule} eq $v
defined $last{$rule} $last{$rule} eq $v
Truth table100%3/3
A and B
A= defined $last{$rule}B= $last{$rule} eq $v
ABresult
0X0
100
111
448 6 $last{$rule} = $v;
449 6 ▶ $cnt{$rule}-- if $cnt{$rule} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $cnt{$rule} > 0 6 0 6
450 6 $kp = 1;
451 }
452 17 ▶ push @{ $kp ? \@k : \@r }, $sn;
Branch: 1 branch
BranchTrueFalseTotal
$kp ? : 6 11 17
453 }
454 5 return ( \@k, \@r );
455 }
456  
457  
458 23 ▶sub restic {
Subroutine restic: called CC=96 SCAR=53.8
Pod documented
459 23 my ( $dev, $av, $ctx ) = @_;
460 23 my @a = @$av;
461 23 ▶ my %env = %{ $Langertha::Holmgang::Sim::Linux::SHENV || {} };
Condition50%1/2
$Langertha::Holmgang::Sim::Linux::SHENV || {}
l!l
230
MC/DC0%0/1
$Langertha::Holmgang::Sim::Linux::SHENV || {}
$Langertha::Holmgang::Sim::Linux::SHENV
Truth table50%1/2
A
A= $Langertha::Holmgang::Sim::Linux::SHENV
Aresult
11
00
462 23 my ( $repo, $pwf, $cmd, %f, %keep, @rest, %o, @inc, @exc );
463 23 $f{$_} = [] for qw( host path tag );
464 23 $repo = $env{RESTIC_REPOSITORY};
465 23 $pwf = $env{RESTIC_PASSWORD_FILE};
466 23 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 93 23 116
467 93 my $x = shift @a;
468 93 ▶ my $val = sub { $x =~ /\A--[\w-]+=(.*)\z/ ? $1 : shift @a };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$x =~ /\A--[\w-]+=(.*)\z/ ? : 0 55 55
469 93 ▶ if ( $x =~ /\A(?:-r|--repo)(?:=|\z)/ ) { $repo = $val->() }
Branch: 13 branches
BranchTrueFalseTotal
if ($x =~ /\A(?:-r|--repo)(?:=|\z)/) { } 22 71 93
elsif ($x =~ /\A(?:-p|--password-file)(?:=|\z)/) { } 21 50 71
elsif ($x =~ /\A--(host|path|tag)(?:=|\z)/) { } 5 45 50
elsif ($x =~ /\A--keep-(last|hourly|daily|weekly|monthly|yearly)(?:=|\z)/) { } 3 42 45
elsif ($x =~ /\A(?:-t|--target)(?:=|\z)/) { } 3 39 42
elsif ($x =~ /\A(?:-i|--include)(?:=|\z)/) { } 1 38 39
elsif ($x =~ /\A(?:-e|--exclude)(?:=|\z)/) { } 0 38 38
elsif ($x =~ /\A--group-by(?:=|\z)/) { } 0 38 38
elsif ($x eq '--prune') { } 1 37 38
elsif ($x eq '--dry-run' or $x eq '-n') { } 0 37 37
elsif ($x eq '--remove-all') { } 0 37 37
elsif ($x =~ /\A-/) { } 0 37 37
elsif (not defined $cmd) { } 23 14 37
470 21 elsif ( $x =~ /\A(?:-p|--password-file)(?:=|\z)/ ) { $pwf = $val->() }
471 5 elsif ( $x =~ /\A--(host|path|tag)(?:=|\z)/ ) { my $k = $1; push @{ $f{$k} }, split /,/, $val->() }
472 3 elsif ( $x =~ /\A--keep-(last|hourly|daily|weekly|monthly|yearly)(?:=|\z)/ ) { my $k = $1; $keep{$k} = $val->() }
473 3 elsif ( $x =~ /\A(?:-t|--target)(?:=|\z)/ ) { $o{target} = $val->() }
474 1 elsif ( $x =~ /\A(?:-i|--include)(?:=|\z)/ ) { push @inc, $val->() }
475 0 elsif ( $x =~ /\A(?:-e|--exclude)(?:=|\z)/ ) { push @exc, $val->() }
476 0 elsif ( $x =~ /\A--group-by(?:=|\z)/ ) { $o{group} = $val->() }
477 1 elsif ( $x eq '--prune' ) { $o{prune} = 1 }
478 0 ▶ elsif ( $x eq '--dry-run' || $x eq '-n' ) { $o{dry} = 1 }
Condition33%1/3
$x eq "--dry-run" or $x eq "-n"
l!l&&r!l&&!r
0037
MC/DC0%0/2
$x eq "--dry-run" or $x eq "-n"
$x eq "--dry-run" $x eq "-n"
Truth table33%1/3
A or B
A= $x eq "--dry-run"B= $x eq "-n"
ABresult
1X1
011
000
479 0 elsif ( $x eq '--remove-all' ) { $o{all} = 1 }
480 elsif ( $x =~ /\A-/ ) { }
481 23 elsif ( !defined $cmd ) { $cmd = $x }
482 14 else { push @rest, $x }
483 }
484 23 ▶ return ( "restic is a backup program which allows saving multiple revisions of files and\ndirectories in an encrypted repository stored on different backends.\n\nUsage:\n restic [command]", 0 ) unless defined $cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cmd 0 23 23
485 23 ▶ return ( 'restic 0.14.0 compiled with go1.19.8 on linux/amd64', 1 ) if $cmd eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "version" 0 23 23
486 23 ▶ return ( 'Fatal: Please specify repository location (-r or --repository-file)', 0 ) unless defined $repo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $repo 0 23 23
487 23 my ( $r, $e ) = _repo( $dev, $ctx, $repo );
488 23 ▶ return ( $e, 0 ) unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 23 23
489 23 ▶ if ( !defined $pwf || _abs($pwf) ne ( $r->{password_file} // '' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $pwf or _abs($pwf) ne ($$r{"password_file"} // "")) 1 22 23
Condition60%3/5
not defined $pwf or _abs($pwf) ne ($$r{"password_file"} // "")
l!l&&r!l&&!r
1022
$$r{"password_file"} // ""
l!l
220
MC/DC50%1/2
not defined $pwf or _abs($pwf) ne ($$r{"password_file"} // "")
not defined $pwf _abs($pwf) ne ($$r{"password_file"} // "")
MC/DC0%0/1
$$r{"password_file"} // ""
$$r{"password_file"}
Truth table66%2/3
not(A) or B
A= not defined $pwfB= _abs($pwf) ne ($$r{"password_file"} // "")
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$r{"password_file"}
Aresult
11
00
490 1 ▶ return ( "Fatal: Load(<password>): open " . _abs($pwf) . ": no such file or directory", 0 ) if defined $pwf && !_entry( $dev, _abs($pwf) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $pwf and not _entry($dev, _abs($pwf)) 0 1 1
Condition33%1/3
defined $pwf and not _entry($dev, _abs($pwf))
!ll&&!rl&&r
100
MC/DC0%0/2
defined $pwf and not _entry($dev, _abs($pwf))
defined $pwf not _entry($dev, _abs($pwf))
Truth table33%1/3
A and not(B)
A= defined $pwfB= not _entry($dev, _abs($pwf))
ABresult
0X0
100
111
491 1 ▶ return ( "Fatal: an empty password is not allowed by default. Pass the flag `--insecure-no-password` to restic to disable this check", 0 ) unless defined $pwf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pwf 1 0 1
492 0 return ( "Fatal: wrong password or no key found", 0 );
493 }
494 22 ▶ if ( $r->{lock} && $cmd !~ /\A(?:unlock|snapshots|ls|dump|cat|stats)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$r{"lock"} and not $cmd =~ /\A(?:unlock|snapshots|ls|dump|cat|stats)\z/) 1 21 22
Condition100%3/3
$$r{"lock"} and not $cmd =~ /\A(?:unlock|snapshots|ls|dump|cat|stats)\z/
!ll&&!rl&&r
2011
MC/DC100%2/2
$$r{"lock"} and not $cmd =~ /\A(?:unlock|snapshots|ls|dump|cat|stats)\z/
$$r{"lock"} not $cmd =~ /\A(?:unlock|snapshots|ls|dump|cat|stats)\z/
Truth table100%3/3
A and not(B)
A= $$r{"lock"}B= not $cmd =~ /\A(?:unlock|snapshots|ls|dump|cat|stats)\z/
ABresult
0X0
100
111
495 1 my $l = $r->{lock};
496 1 return ( "repository is already locked by PID $l->{pid} on $l->{host} by root (UID 0, GID 0)\nlock was created at $l->{time} (12h29m55s ago)\nstorage ID 8a1b2c3d\nthe `unlock` command can be used to remove stale locks", 0 );
497 }
498 21 ▶ my @snaps = @{ $r->{snapshots} || [] };
Condition50%1/2
$$r{'snapshots'} || []
l!l
210
MC/DC0%0/1
$$r{'snapshots'} || []
$$r{'snapshots'}
Truth table50%1/2
A
A= $$r{'snapshots'}
Aresult
11
00
499 21 ▶ if ( $cmd eq 'snapshots' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "snapshots") 4 17 21
500 4 my @s = sort { $a->{time} cmp $b->{time} } _sel( \@snaps, %f );
501 4 my $hr = '-' x 74;
502 4 return ( join( "\n", sprintf( '%-9s %-20s %-11s %-11s %s', 'ID', 'Time', 'Host', 'Tags', 'Paths' ), $hr, ( map { _snap_line($_) } @s ), $hr,
503 scalar(@s) . ' snapshots' ), 1 );
504 }
505 17 ▶ if ( $cmd eq 'unlock' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "unlock") 1 16 17
506 1 ▶ delete $r->{lock} if $r->{lock};
Branch: 1 branch
BranchTrueFalseTotal
if $$r{"lock"} 1 0 1
507 1 return ( 'successfully removed 1 locks', 1 );
508 }
509 0 ▶ if ( $cmd eq 'check' ) { return ( "using temporary cache in /tmp/restic-check-cache-1\ncreated new cache in /tmp/restic-check-cache-1\nload indexes\ncheck all packs\ncheck snapshots, trees and blobs\nno errors were found", 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "check") 0 16 16
510 16 ▶ if ( $cmd eq 'stats' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "stats") 0 16 16
511 return ( "repository 3c1f2e9a opened (version 2, compression level auto)\nscanning...\nStats in restore-size mode:\n Snapshots processed: " . scalar(@snaps)
512 0 ▶ . "\n Total File Count: " . ( 0 + map { keys %{ $_->{files} || {} } } @snaps ) . "\n Total Size: $r->{size}", 1 );
Condition0%0/2
$$_{'files'} || {}
l!l
00
MC/DC0%0/1
$$_{'files'} || {}
$$_{'files'}
Truth table0%0/2
A
A= $$_{'files'}
Aresult
11
00
513 }
514 16 ▶ if ( $cmd eq 'ls' || $cmd eq 'dump' || $cmd eq 'restore' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "ls" or $cmd eq "dump" or $cmd eq "restore") 7 9 16
Condition100%6/6
$cmd eq "ls" or $cmd eq "dump" or $cmd eq "restore"
l!l&&r!l&&!r
439
$cmd eq "ls" or $cmd eq "dump"
l!l&&r!l&&!r
3112
MC/DC100%3/3
$cmd eq "ls" or $cmd eq "dump" or $cmd eq "restore"
$cmd eq "ls" $cmd eq "dump" $cmd eq "restore"
Truth table100%4/4
A or B or C
A= $cmd eq "ls"B= $cmd eq "dump"C= $cmd eq "restore"
ABCresult
1XX1
01X1
0011
0000
515 7 ▶ my $id = shift(@rest) // return ( "Fatal: no snapshot ID specified", 0 );
Condition50%1/2
shift @rest // (return "Fatal: no snapshot ID specified", 0)
l!l
70
MC/DC0%0/1
shift @rest // (return "Fatal: no snapshot ID specified", 0)
shift @rest
Truth table50%1/2
A
A= shift @rest
Aresult
11
00
516 7 ▶ my $s = _find_snap( $r, $id, %f ) or return ( "Fatal: invalid id \"$id\": no matching ID found for prefix \"$id\"", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $s = _find_snap($r, $id, %f) or return qq[Fatal: invalid id "$id": no matching ID found for prefix "$id"], 0 7 0 7
517 7 ▶ my %files = %{ $s->{files} || {} };
Condition50%1/2
$$s{'files'} || {}
l!l
70
MC/DC0%0/1
$$s{'files'} || {}
$$s{'files'}
Truth table50%1/2
A
A= $$s{'files'}
Aresult
11
00
518 7 ▶ if ( $cmd eq 'ls' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "ls") 3 4 7
519 3 my ($under) = @rest;
520 3 ▶ my @n = sort grep { !defined $under || $_ eq $under || index( $_, "$under/" ) == 0 } keys %files;
Condition33%2/6
!defined($under) || $_ eq $under || index($_, "$under/") == 0
l!l&&r!l&&!r
300
not defined $under or $_ eq $under
l!l&&r!l&&!r
300
MC/DC0%0/3
!defined($under) || $_ eq $under || index($_, "$under/") == 0
not defined $under $_ eq $under index($_, "$under/") == 0
Truth table25%1/4
not(A) or B || C
A= not defined $underB= $_ eq $underC= index($_, "$under/") == 0
ABCresult
1XX1
01X1
0011
0000
521 3 ▶ return ( join( "\n", "snapshot " . substr( $s->{id}, 0, 8 ) . " of [@{ $s->{paths} || [] }] at $s->{time}):", @n ), 1 );
Condition100%2/2
$$s{'paths'} || []
l!l
12
MC/DC100%1/1
$$s{'paths'} || []
$$s{'paths'}
Truth table100%2/2
A
A= $$s{'paths'}
Aresult
11
00
522 }
523 4 ▶ if ( $cmd eq 'dump' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "dump") 1 3 4
524 1 ▶ my $p = shift(@rest) // return ( 'Fatal: no file and no snapshot ID specified', 0 );
Condition50%1/2
shift @rest // (return "Fatal: no file and no snapshot ID specified", 0)
l!l
10
MC/DC0%0/1
shift @rest // (return "Fatal: no file and no snapshot ID specified", 0)
shift @rest
Truth table50%1/2
A
A= shift @rest
Aresult
11
00
525 1 ▶ my $fe = $files{$p} or return ( "Fatal: cannot dump file: path \"$p\" not found in snapshot", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $fe = $files{$p} or return qq[Fatal: cannot dump file: path "$p" not found in snapshot], 0 1 0 1
526 1 ▶ return ( ( ref $fe ? $fe->{content} // '' : $fe ) =~ s/\n\z//r, 1 );
Branch: 1 branch
BranchTrueFalseTotal
ref $fe ? : 1 0 1
Condition50%1/2
$$fe{"content"} // ""
l!l
10
MC/DC0%0/1
$$fe{"content"} // ""
$$fe{"content"}
Truth table50%1/2
A
A= $$fe{"content"}
Aresult
11
00
527 }
528 3 ▶ return ( 'Fatal: Please specify a directory to restore to (--target)', 0 ) unless defined $o{target};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o{"target"} 0 3 3
529 3 my $tg = _abs( $o{target} );
530 1 ▶ my $match = sub {
Subroutine __ANON__: called CC=4 SCAR=16.1
531 1 my ( $p, $pats ) = @_;
532 1 for my $q (@$pats) {
533 1 ( my $re = quotemeta( $q =~ s{/+\z}{}r ) ) =~ s/\\\*/[^\/]*/g;
534 1 ▶ return 1 if $p =~ /\A$re(?:\/|\z)/ || $p =~ /(?:\A|\/)$re\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $p =~ m[\A$re(?:/|\z)] or $p =~ m[(?:\A|/)$re\z] 1 0 1
Condition33%1/3
$p =~ m[\A$re(?:/|\z)] or $p =~ m[(?:\A|/)$re\z]
l!l&&r!l&&!r
100
MC/DC0%0/2
$p =~ m[\A$re(?:/|\z)] or $p =~ m[(?:\A|/)$re\z]
$p =~ m[\A$re(?:/|\z)] $p =~ m[(?:\A|/)$re\z]
Truth table33%1/3
A or B
A= $p =~ m[\A$re(?:/|\z)]B= $p =~ m[(?:\A|/)$re\z]
ABresult
1X1
011
000
535 }
536 0 return 0;
537 3 };
538 3 my $n = 0;
539 3 for my $p ( sort keys %files ) {
540 3 ▶ next if @inc && !$match->( $p, \@inc );
Branch: 1 branch
BranchTrueFalseTotal
if @inc and not &$match($p, \@inc) 0 3 3
Condition66%2/3
@inc and not &$match($p, \@inc)
!ll&&!rl&&r
210
MC/DC0%0/2
@inc and not &$match($p, \@inc)
@inc not &$match($p, \@inc)
Truth table66%2/3
A and not(B)
A= @incB= not &$match($p, \@inc)
ABresult
0X0
100
111
541 3 ▶ next if @exc && $match->( $p, \@exc );
Branch: 1 branch
BranchTrueFalseTotal
if @exc and &$match($p, \@exc) 0 3 3
Condition33%1/3
@exc and &$match($p, \@exc)
!ll&&!rl&&r
300
MC/DC0%0/2
@exc and &$match($p, \@exc)
@exc &$match($p, \@exc)
Truth table33%1/3
A and B
A= @excB= &$match($p, \@exc)
ABresult
0X0
100
111
542 3 ▶ _put( $dev, ( $tg eq '/' ? '' : $tg ) . $p, copy_entry( $files{$p}, 1 ) );
Branch: 1 branch
BranchTrueFalseTotal
$tg eq '/' ? : 1 2 3
543 3 $n++;
544 }
545 3 ▶ return ( "Fatal: there are no files to restore", 0 ) if !$n && @inc;
Branch: 1 branch
BranchTrueFalseTotal
if not $n and @inc 0 3 3
Condition33%1/3
not $n and @inc
!ll&&!rl&&r
300
MC/DC0%0/2
not $n and @inc
not $n @inc
Truth table33%1/3
not(A) and B
A= not $nB= @inc
ABresult
0X0
100
111
546 3 ▶ return ( "repository 3c1f2e9a opened (version 2, compression level auto)\nrestoring <Snapshot " . substr( $s->{id}, 0, 8 ) . " of [@{ $s->{paths} || [] }] at $s->{time} by root\@$s->{host}> to $tg\nSummary: Restored $n files/dirs", 1 );
Condition100%2/2
$$s{'paths'} || []
l!l
21
MC/DC100%1/1
$$s{'paths'} || []
$$s{'paths'}
Truth table100%2/2
A
A= $$s{'paths'}
Aresult
11
00
547 }
548 9 ▶ if ( $cmd eq 'forget' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "forget") 7 2 9
549 7 my @l;
550 my %gone;
551 7 ▶ if (@rest) {
Branch: 1 branch
BranchTrueFalseTotal
if (@rest) { } 4 3 7
552 4 for my $id (@rest) {
553 4 ▶ my $s = _find_snap( $r, $id, %f ) or return ( "Fatal: invalid id \"$id\": no matching ID found for prefix \"$id\"", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $s = _find_snap($r, $id, %f) or return qq[Fatal: invalid id "$id": no matching ID found for prefix "$id"], 0 3 0 3
554 3 $gone{ $s->{id} } = 1;
555 3 push @l, "removed snapshot " . substr( $s->{id}, 0, 8 );
556 }
557 }
558 else {
559 3 ▶ return ( 'no policy was specified, no snapshots will be removed', 1 ) unless %keep;
Branch: 1 branch
BranchTrueFalseTotal
unless %keep 0 3 3
560 3 ▶ for my $k ( values %keep ) { return ( "Fatal: invalid argument \"$k\"", 0 ) unless $k =~ /\A\d+\z/ }
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /\A\d+\z/ 0 3 3
561 3 ▶ my @by = split /,/, $o{group} // 'host,paths';
Condition50%1/2
$o{"group"} // "host,paths"
l!l
03
MC/DC0%0/1
$o{"group"} // "host,paths"
$o{"group"}
Truth table50%1/2
A
A= $o{"group"}
Aresult
11
00
562 3 my %grp;
563 3 for my $s ( _sel( \@snaps, %f ) ) {
564 0 ▶ my $key = join '|', map { $_ eq 'host' ? $s->{host} : $_ eq 'paths' ? join( ',', sort @{ $s->{paths} || [] } ) : $_ eq 'tags' ? join( ',', sort @{ $s->{tags} || [] } ) : '' } @by;
Branch: 3 branches
BranchTrueFalseTotal
$_ eq 'host' ? : 17 17 34
$_ eq 'paths' ? : 17 0 17
$_ eq 'tags' ? : 0 0 0
Condition50%2/4
$$s{'paths'} || []
l!l
116
$$s{'tags'} || []
l!l
00
MC/DC100%1/1
$$s{'paths'} || []
$$s{'paths'}
MC/DC0%0/1
$$s{'tags'} || []
$$s{'tags'}
Truth table100%2/2
A
A= $$s{'paths'}
Aresult
11
00
Truth table0%0/2
A
A= $$s{'tags'}
Aresult
11
00
565 17 push @{ $grp{$key} }, $s;
566 }
567 3 push @l, 'Applying Policy: keep ' . join( ', ', map {"$keep{$_} $_ snapshots"} sort keys %keep );
568 3 for my $g ( sort keys %grp ) {
569 5 my ( $k, $rm ) = _policy( $grp{$g}, \%keep );
570 10 push @l, "snapshots for (" . join( ', ', map { my $i = $_; $i } @by ) . " [$g]):", "keep " . scalar(@$k) . ' snapshots:',
571 6 ▶ ( map { _snap_line($_) } sort { $a->{time} cmp $b->{time} } @$k ),
Branch: 1 branch
BranchTrueFalseTotal
@$rm ? : 3 2 5
572 5 ( @$rm ? ( 'remove ' . scalar(@$rm) . ' snapshots:', map { _snap_line($_) } sort { $a->{time} cmp $b->{time} } @$rm ) : () ), '';
573 5 $gone{ $_->{id} } = 1 for @$rm;
574 }
575 }
576 6 ▶ unless ( $o{dry} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o{"dry"}) 6 0 6
577 6 my $free = 0;
578 6 ▶ $free += _L( '_bytes', $_->{unique} // 0 ) for grep { $gone{ $_->{id} } } @snaps;
Condition100%2/2
$$_{"unique"} // 0
l!l
131
MC/DC100%1/1
$$_{"unique"} // 0
$$_{"unique"}
Truth table100%2/2
A
A= $$_{"unique"}
Aresult
11
00
579 6 $r->{snapshots} = [ grep { !$gone{ $_->{id} } } @snaps ];
580 6 ▶ $r->{prunable} = _L( '_human', _L( '_bytes', $r->{prunable} // 0 ) + $free ) if $free;
Branch: 1 branch
BranchTrueFalseTotal
if $free 5 1 6
Condition100%2/2
$$r{"prunable"} // 0
l!l
14
MC/DC100%1/1
$$r{"prunable"} // 0
$$r{"prunable"}
Truth table100%2/2
A
A= $$r{"prunable"}
Aresult
11
00
581 6 ▶ push @l, _prune($r) if $o{prune};
Branch: 1 branch
BranchTrueFalseTotal
if $o{"prune"} 1 5 6
582 }
583 6 return ( join( "\n", @l ), 1 );
584 }
585 2 ▶ if ( $cmd eq 'prune' ) { return ( _prune($r), 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "prune") 1 1 2
586 1 ▶ if ( $cmd eq 'backup' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd eq "backup") 1 0 1
587 1 ▶ return ( 'Fatal: nothing to backup, please specify source files/dirs', 0 ) unless @rest;
Branch: 1 branch
BranchTrueFalseTotal
unless @rest 0 1 1
588 1 my %files;
589 1 my @paths = map { _abs($_) =~ s{(?<=.)/+\z}{}r } @rest;
590 1 for my $p (@paths) {
591 1 ▶ my @fs = _entry( $dev, $p ) ? ($p) : _L( '_under', $dev, $p );
Branch: 1 branch
BranchTrueFalseTotal
_entry($dev, $p) ? : 0 1 1
592 1 ▶ return ( "Fatal: unable to save snapshot: lstat $p: no such file or directory", 0 ) unless @fs;
Branch: 1 branch
BranchTrueFalseTotal
unless @fs 0 1 1
593 1 $files{$_} = copy_entry( _entry( $dev, $_ ), 1 ) for @fs;
594 }
595 0 for my $x (@exc) { delete $files{$_} for grep { index( $_, $x =~ s{/+\z}{}r ) == 0 } keys %files }
596 1 my $id = substr( Digest::SHA::sha256_hex( JSON::MaybeXS->new( canonical => 1 )->encode( [ \%files, scalar @snaps ] ) ), 0, 8 );
597 1 ▶ push @{ $r->{snapshots} }, { id => $id, time => '2026-10-20 12:00:00', host => $dev->{hostname} // $ctx->{host}, paths => [ sort @paths ], tags => [], files => \%files };
Condition33%1/3
$$dev{"hostname"} // $$ctx{"host"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$$dev{"hostname"} // $$ctx{"host"}
$$dev{"hostname"} $$ctx{"host"}
Truth table33%1/3
A // B
A= $$dev{"hostname"}B= $$ctx{"host"}
ABresult
1X1
011
000
598 1 ▶ return ( "repository 3c1f2e9a opened (version 2, compression level auto)\nusing parent snapshot " . ( @snaps ? substr( $snaps[-1]{id}, 0, 8 ) : '' )
Branch: 1 branch
BranchTrueFalseTotal
@snaps ? : 1 0 1
599 . "\n\nFiles: " . scalar( keys %files ) . " new, 0 changed, 0 unmodified\nAdded to the repository: 12.204 MiB\n\nsnapshot $id saved", 1 );
600 }
601 0 return ( "Error: unknown command \"$cmd\" for \"restic\"\nRun 'restic --help' for usage.", 0 );
602 }
603  
604 2 ▶sub _prune {
Subroutine _prune: called CC=5 SCAR=17.2
605 2 my ($r) = @_;
606 2 ▶ my $p = _L( '_bytes', $r->{prunable} // 0 );
Condition50%1/2
$$r{"prunable"} // 0
l!l
20
MC/DC0%0/1
$$r{"prunable"} // 0
$$r{"prunable"}
Truth table50%1/2
A
A= $$r{"prunable"}
Aresult
11
00
607 2 ▶ my $s = _L( '_bytes', $r->{size} // 0 );
Condition50%1/2
$$r{"size"} // 0
l!l
20
MC/DC0%0/1
$$r{"size"} // 0
$$r{"size"}
Truth table50%1/2
A
A= $$r{"size"}
Aresult
11
00
608 2 ▶ $r->{size} = _L( '_human', $s - $p > 0 ? $s - $p : 0 ) if $p;
Branch: 2 branches
BranchTrueFalseTotal
if $p 2 0 2
$s - $p > 0 ? : 2 0 2
609 2 delete $r->{prunable};
610 2 return "loading indexes...\nfinding data that is still in use for snapshots\nsearching used packs...\ncollecting packs for deletion and repacking\nto delete: " . _L( '_human', $p ) . "\ndone";
611 }
612  
613 8 1;
614  
615 __END__
« blib/lib/Langertha/Holmgang/Structure.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Dns.pm »