| 1 | package Brackup::Restore; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use Digest::SHA1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use POSIX qw(mkfifo); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Fcntl qw(O_RDONLY O_CREAT O_WRONLY O_TRUNC); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use String::Escape qw(unprintable); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Brackup::DecryptedFile; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 13 | ▶ | use Brackup::Decrypt; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | my ($class, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 7 | $self->{to} = delete $opts{to}; # directory we're restoring to | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | $self->{prefix} = delete $opts{prefix}; # directory/file filename prefix, or "" for all | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | $self->{filename}= delete $opts{file}; # filename we're restoring from | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | $self->{config} = delete $opts{config}; # brackup config (if available) | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 7 | $self->{verbose} = delete $opts{verbose}; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | $self->{_local_uid_map} = {}; # remote/metafile uid -> local uid | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | $self->{_local_gid_map} = {}; # remote/metafile gid -> local gid | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | $self->{prefix} =~ s/\/$// if $self->{prefix}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | $self->{_stats_to_run} = []; # stack (push/pop) of subrefs to reset stat info on | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 7 | ▶ | die "Destination directory doesn't exist" unless $self->{to} && -d $self->{to}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"to"} and -d $self->{"to"}
MC/DC0%0/2
$self->{"to"} and -d $self->{"to"}
$self->{"to"}
-d $self->{"to"}
Truth table33%1/3
A and B
A= $self->{"to"}B= -d $self->{"to"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | croak("Unknown options: " . join(', ', keys %opts)) if %opts; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | $self->{metafile} = Brackup::DecryptedFile->new(filename => $self->{filename}); | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # returns a hashref of { "foo" => "bar" } from { ..., "Driver-foo" => "bar" } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | ▶ | sub _driver_meta { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_driver_meta: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | my $src = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 7 | my $ret = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | foreach my $k (keys %$src) { | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | 91 | ▶ | next unless $k =~ /^Driver-(.+)/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 14 | $ret->{$1} = $src->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | return $ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 7 | ▶ | sub restore { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restore: called CC=39 SCAR=39.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 7 | my $parser = $self->parser; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 7 | my $meta = $parser->readline; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | my $driver_class = $meta->{BackupDriver}; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | ▶ | die "No driver specified" unless $driver_class; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | my $driver_meta = _driver_meta($meta); | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 7 | my $confsec; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | ▶ | if ($self->{config} && $meta->{TargetName}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"config"} and $meta->{"TargetName"}
MC/DC0%0/2
$self->{"config"} and $meta->{"TargetName"}
$self->{"config"}
$meta->{"TargetName"}
Truth table33%1/3
A and B
A= $self->{"config"}B= $meta->{"TargetName"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $confsec = eval { $self->{config}->get_section('TARGET:' . $meta->{TargetName}) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # If no config section, use an empty one up with no keys to simplify Target handling | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | ▶ | $confsec ||= Brackup::ConfigSection->new('fake'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$confsec ||= "Brackup::ConfigSection"->new("fake")
MC/DC0%0/2
$confsec ||= "Brackup::ConfigSection"->new("fake")
$confsec
"Brackup::ConfigSection"->new("fake")
Truth table33%1/3
A ||= B
A= $confsecB= "Brackup::ConfigSection"->new("fake")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 7 | ▶ | eval "use $driver_class; 1;" or die | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | "Failed to load driver ($driver_class) to restore from: $@\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 7 | my $target = eval {"$driver_class"->new_from_backup_header($driver_meta, $confsec); }; | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | die "Failed to instantiate target ($driver_class) for restore. Perhaps it doesn't support restoring yet?\n\nThe error was: $@"; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 7 | $self->{_target} = $target; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 7 | $self->{_meta} = $meta; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # handle absolute prefixes by stripping off RootPath to relativise | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | ▶ | if ($self->{prefix} && $self->{prefix} =~ m/^\//) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"prefix"} and $self->{"prefix"} =~ m[^/]
MC/DC0%0/2
$self->{"prefix"} and $self->{"prefix"} =~ m[^/]
$self->{"prefix"}
$self->{"prefix"} =~ m[^/]
Truth table66%2/3
A and B
A= $self->{"prefix"}B= $self->{"prefix"} =~ m[^/]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->{prefix} =~ s/^\Q$meta->{RootPath}\E\/?//; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # we first process directories, then files sorted by their first chunk, | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # then the rest. The file sorting allows us to avoid loading composite | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # chunks and identical single chunk files multiple times from the target | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # (see _restore_file) | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 7 | my (@dirs, @files, @rest); | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | ▶ | while (my $it = $parser->readline) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 100 | ▶ | my $type = $it->{Type} || 'f'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$it->{'Type'} || 'f'
MC/DC100%1/1
$it->{'Type'} || 'f'
$it->{'Type'}
Truth table100%2/2
A
A= $it->{'Type'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 100 | ▶ | if($type eq 'f') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # find dig of first chunk | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 81 | ▶ | ($it->{Chunks} || '') =~ /^(\S+)/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$it->{'Chunks'} || ''
MC/DC0%0/1
$it->{'Chunks'} || ''
$it->{'Chunks'}
Truth table50%1/2
A
A= $it->{'Chunks'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 81 | ▶ | my ($offset, $len, $enc_len, $dig) = split(/;/, $1 || ''); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$1 || ''
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 81 | ▶ | $it->{fst_dig} = $dig || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$dig || ''
MC/DC0%0/1
$dig || ''
$dig
Truth table50%1/2
A
A= $dig
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 81 | push @files, $it; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } elsif($type eq 'd') { | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 19 | push @dirs, $it; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | push @rest, $it; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 7 | @files = sort { $a->{fst_dig} cmp $b->{fst_dig} } @files; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 7 | my $restore_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | 7 | for my $it (@dirs, @files, @rest) { | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 100 | ▶ | my $type = $it->{Type} || "f"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$it->{'Type'} || 'f'
MC/DC100%1/1
$it->{'Type'} || 'f'
$it->{'Type'}
Truth table100%2/2
A
A= $it->{'Type'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 100 | my $path = unprintable($it->{Path}); | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 100 | my $path_escaped = $it->{Path}; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 100 | my $path_escaped_stripped = $it->{Path}; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 100 | ▶ | die "Unknown filetype: type=$type, file: $path_escaped" unless $type =~ /^[ldfp]$/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 100 | ▶ | if ($self->{prefix}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 60 | ▶ | next unless $path =~ m/^\Q$self->{prefix}\E(?:\/|$)/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # if non-dir and $path eq $self->{prefix}, strip all but last component | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | if ($type ne 'd' && $path =~ m/^\Q$self->{prefix}\E\/?$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type ne "d" and $path =~ m[^\Q$self->{"prefix"}\E/?$]
MC/DC100%2/2
$type ne "d" and $path =~ m[^\Q$self->{"prefix"}\E/?$]
$type ne "d"
$path =~ m[^\Q$self->{"prefix"}\E/?$]
Truth table100%3/3
A and B
A= $type ne "d"B= $path =~ m[^\Q$self->{"prefix"}\E/?$]
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | if (my ($leading_prefix) = ($self->{prefix} =~ m/^(.*\/)[^\/]+\/?$/)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | $path =~ s/^\Q$leading_prefix\E//; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | $path_escaped_stripped =~ s/^\Q$leading_prefix\E//; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 116 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | $path =~ s/^\Q$self->{prefix}\E\/?//; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | $path_escaped_stripped =~ s/^\Q$self->{prefix}\E\/?//; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 46 | $restore_count++; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 46 | my $full = $self->{to} . "/" . $path; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 46 | my $full_escaped = $self->{to} . "/" . $path_escaped_stripped; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # restore default modes/user/group from header | ||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 46 | ▶ | $it->{Mode} ||= ($type eq 'd' ? $meta->{DefaultDirMode} : $meta->{DefaultFileMode}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$it->{"Mode"} ||= $type eq "d" ? $meta->{"DefaultDirMode"} : $meta->{"DefaultFileMode"}
MC/DC0%0/2
$it->{"Mode"} ||= $type eq "d" ? $meta->{"DefaultDirMode"} : $meta->{"DefaultFileMode"}
$it->{"Mode"}
$type eq "d" ? $meta->{"DefaultDirMode"} : $meta->{"DefaultFileMode"}
Truth table66%2/3
A ||= B
A= $it->{"Mode"}B= $type eq "d" ? $meta->{"DefaultDirMode"} : $meta->{"DefaultFileMode"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 46 | ▶ | $it->{UID} ||= $meta->{DefaultUID}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$it->{"UID"} ||= $meta->{"DefaultUID"}
MC/DC0%0/2
$it->{"UID"} ||= $meta->{"DefaultUID"}
$it->{"UID"}
$meta->{"DefaultUID"}
Truth table33%1/3
A ||= B
A= $it->{"UID"}B= $meta->{"DefaultUID"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 46 | ▶ | $it->{GID} ||= $meta->{DefaultGID}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$it->{"GID"} ||= $meta->{"DefaultGID"}
MC/DC0%0/2
$it->{"GID"} ||= $meta->{"DefaultGID"}
$it->{"GID"}
$meta->{"DefaultGID"}
Truth table33%1/3
A ||= B
A= $it->{"GID"}B= $meta->{"DefaultGID"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 46 | ▶ | warn " * restoring $path_escaped to $full_escaped\n" if $self->{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 46 | ▶ | $self->_restore_link ($full, $it) if $type eq "l"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 46 | ▶ | $self->_restore_directory($full, $it) if $type eq "d"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 46 | ▶ | $self->_restore_fifo ($full, $it) if $type eq "p"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 46 | ▶ | $self->_restore_file ($full, $it) if $type eq "f"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 46 | ▶ | $self->_chown($full, $it, $type, $meta) if $it->{UID} || $it->{GID}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$it->{"UID"} or $it->{"GID"}
MC/DC0%0/2
$it->{"UID"} or $it->{"GID"}
$it->{"UID"}
$it->{"GID"}
Truth table33%1/3
A or B
A= $it->{"UID"}B= $it->{"GID"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # clear chunk cached by _restore_file | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | delete $self->{_cached_dig}; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | 7 | delete $self->{_cached_dataref}; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 7 | ▶ | if ($restore_count) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | ▶ | warn " * fixing stat info\n" if $self->{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 6 | $self->_exec_statinfo_updates; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 6 | ▶ | warn " * done\n" if $self->{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | die "nothing found matching '$self->{prefix}'.\n" if $self->{prefix}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | die "nothing found to restore.\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 46 | ▶ | sub _lookup_remote_uid { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lookup_remote_uid: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 46 | my ($self, $remote_uid, $meta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | return $self->{_local_uid_map}->{$remote_uid} | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 46 | ▶ | if defined $self->{_local_uid_map}->{$remote_uid}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # meta remote user map - remote_uid => remote username | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 6 | ▶ | $self->{_remote_user_map} ||= { map { split /:/, $_, 2 } split /\s+/, $meta->{UIDMap} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_remote_user_map"} ||= {map({split(/:/, $_, 2);} split(/\s+/, $meta->{"UIDMap"}, 0))}
MC/DC0%0/1
$self->{"_remote_user_map"} ||= {map({split(/:/, $_, 2);} split(/\s+/, $meta->{"UIDMap"}, 0))}
$self->{"_remote_user_map"}
Truth table50%1/2
A
A= $self->{"_remote_user_map"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # try and lookup local uid using remote username | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 6 | ▶ | if (my $remote_user = $self->{_remote_user_map}->{$remote_uid}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 6 | my $local_uid = getpwnam($remote_user); | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 6 | ▶ | return $self->{_local_uid_map}->{$remote_uid} = $local_uid | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | if defined $local_uid; | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # if remote username missing locally, fallback to $remote_uid | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | return $self->{_local_uid_map}->{$remote_uid} = $remote_uid; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 46 | ▶ | sub _lookup_remote_gid { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lookup_remote_gid: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 46 | my ($self, $remote_gid, $meta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | return $self->{_local_gid_map}->{$remote_gid} | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 46 | ▶ | if defined $self->{_local_gid_map}->{$remote_gid}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # meta remote group map - remote_gid => remote group | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 6 | ▶ | $self->{_remote_group_map} ||= { map { split /:/, $_, 2 } split /\s+/, $meta->{GIDMap} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_remote_group_map"} ||= {map({split(/:/, $_, 2);} split(/\s+/, $meta->{"GIDMap"}, 0))}
MC/DC0%0/1
$self->{"_remote_group_map"} ||= {map({split(/:/, $_, 2);} split(/\s+/, $meta->{"GIDMap"}, 0))}
$self->{"_remote_group_map"}
Truth table50%1/2
A
A= $self->{"_remote_group_map"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # try and lookup local gid using remote group | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 6 | ▶ | if (my $remote_group = $self->{_remote_group_map}->{$remote_gid}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 6 | my $local_gid = getgrnam($remote_group); | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 6 | ▶ | return $self->{_local_gid_map}->{$remote_gid} = $local_gid | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 188 | if defined $local_gid; | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # if remote group missing locally, fallback to $remote_gid | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return $self->{_local_gid_map}->{$remote_gid} = $remote_gid; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 46 | ▶ | sub _chown { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_chown: called CC=11 SCAR=36.1
| |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 46 | my ($self, $full, $it, $type, $meta) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 46 | ▶ | my $uid = $self->_lookup_remote_uid($it->{UID}, $meta) if $it->{UID}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 46 | ▶ | my $gid = $self->_lookup_remote_gid($it->{GID}, $meta) if $it->{GID}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 46 | ▶ | if ($type eq 'l') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | if (! defined $self->{_lchown}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 13 | ▶ | no strict 'subs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | $self->{_lchown} = eval { require Lchown } && Lchown::LCHOWN_AVAILABLE; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
require Lchown
}
} && 'Lchown::LCHOWN_AVAILABLE'
MC/DC0%0/1
eval {
do {
require Lchown
}
} && 'Lchown::LCHOWN_AVAILABLE'
eval {
do {
require Lchown
}
}
Truth table0%0/2
A
A= eval {
do {
require Lchown
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | if ($self->{_lchown}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | Lchown::lchown($uid, -1, $full) if defined $uid; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | Lchown::lchown(-1, $gid, $full) if defined $gid; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # ignore errors, but change uid and gid separately to sidestep unprivileged failures | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 46 | ▶ | chown $uid, -1, $full if defined $uid; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 46 | ▶ | chown -1, $gid, $full if defined $gid; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 46 | ▶ | sub _update_statinfo { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_statinfo: called CC=1 SCAR=0.7
| |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 46 | my ($self, $full, $it) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 46 | ▶ | push @{ $self->{_stats_to_run} }, sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 46 | ▶ | if (defined $it->{Mode}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 46 | ▶ | chmod(oct $it->{Mode}, $full) or | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | die "Failed to change mode of $full: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 46 | ▶ | if ($it->{Mtime} || $it->{Atime}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$it->{"Mtime"} or $it->{"Atime"}
MC/DC0%0/2
$it->{"Mtime"} or $it->{"Atime"}
$it->{"Mtime"}
$it->{"Atime"}
Truth table33%1/3
A or B
A= $it->{"Mtime"}B= $it->{"Atime"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | utime($it->{Atime} || $it->{Mtime}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | $it->{Mtime} || $it->{Atime}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 46 | ▶ | $full) or | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$it->{'Atime'} || $it->{'Mtime'}
$it->{'Mtime'} || $it->{'Atime'}
MC/DC0%0/2
$it->{'Atime'} || $it->{'Mtime'}
$it->{'Atime'}
$it->{'Mtime'}
MC/DC0%0/2
$it->{'Mtime'} || $it->{'Atime'}
$it->{'Mtime'}
$it->{'Atime'}
Truth table33%1/3
A || B
A= $it->{'Atime'}B= $it->{'Mtime'}
Truth table33%1/3
A || B
A= $it->{'Mtime'}B= $it->{'Atime'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | die "Failed to change utime of $full: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 46 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 6 | ▶ | sub _exec_statinfo_updates { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exec_statinfo_updates: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # change the modes/times in backwards order, going from deep | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # files/directories to shallow ones. (so we can reliably change | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # all the directory mtimes without kernel doing it for us when we | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | # modify files deeper) | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 6 | ▶ | while (my $sb = pop @{ $self->{_stats_to_run} }) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 46 | $sb->(); | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 9 | ▶ | sub _restore_directory { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_restore_directory: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 9 | my ($self, $full, $it) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 9 | ▶ | unless (-d $full) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 5 | ▶ | mkdir $full or # FIXME: permissions on directory | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | die "Failed to make directory: $full ($it->{Path})"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 9 | $self->_update_statinfo($full, $it); | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub _restore_link { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_restore_link: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my ($self, $full, $it) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | if (-e $full) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # TODO: add --conflict={skip,overwrite} option, defaulting to nothing: which dies | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | die "Link $full ($it->{Path}) already exists. Aborting."; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | symlink $it->{Link}, $full | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | or die "Failed to link"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | sub _restore_fifo { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_restore_fifo: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my ($self, $full, $it) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (-e $full) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | die "Named pipe/fifo $full ($it->{Path}) already exists. Aborting."; | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | mkfifo($full, $it->{Mode}) or die "mkfifo failed: $!"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $self->_update_statinfo($full, $it); | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 37 | ▶ | sub _restore_file { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_restore_file: called CC=20 SCAR=33.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 37 | my ($self, $full, $it) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 37 | ▶ | if (-e $full && -s $full) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $full and -s $full
MC/DC0%0/2
-e $full and -s $full
-e $full
-s $full
Truth table33%1/3
A and B
A= -e $fullB= -s $full
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # TODO: add --conflict={skip,overwrite} option, defaulting to nothing: which dies | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | die "File $full ($it->{Path}) already exists. Aborting."; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 37 | ▶ | sysopen(my $fh, $full, O_CREAT|O_WRONLY|O_TRUNC) or die "Failed to open '$full' for writing: $!"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 37 | binmode($fh); | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | 37 | ▶ | my @chunks = grep { $_ } split(/\s+/, $it->{Chunks} || ""); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$it->{'Chunks'} || ''
MC/DC0%0/1
$it->{'Chunks'} || ''
$it->{'Chunks'}
Truth table50%1/2
A
A= $it->{'Chunks'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 37 | foreach my $ch (@chunks) { | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | 45 | my ($offset, $len, $enc_len, $dig) = split(/;/, $ch); | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # we process files sorted by the dig of their first chunk, caching | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # the last seen chunk to avoid loading composite chunks multiple | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # times (all files included in composite chunks are single-chunk | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # files, by definition). Even for non-composite chunks there is a | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | # speedup if we have single-chunk identical files. | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 45 | my $dataref; | |||||||||||||||||||||||||||||||||||||||||||||
| 301 | 45 | ▶ | if($dig eq ($self->{_cached_dig} || '')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->{'_cached_dig'} || ''
MC/DC100%1/1
$self->{'_cached_dig'} || ''
$self->{'_cached_dig'}
Truth table100%2/2
A
A= $self->{'_cached_dig'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 10 | ▶ | warn " ** using cached chunk $dig\n" if $self->{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 10 | $dataref = $self->{_cached_dataref}; | |||||||||||||||||||||||||||||||||||||||||||||
| 304 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 35 | ▶ | warn " ** loading chunk $dig from target\n" if $self->{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 35 | ▶ | $dataref = $self->{_target}->load_chunk($dig) or | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | die "Error loading chunk $dig from the restore target\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 35 | $self->{_cached_dig} = $dig; | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | 35 | $self->{_cached_dataref} = $dataref; | |||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 45 | my $len_chunk = length $$dataref; | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # using just a range of the file | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 45 | ▶ | if ($enc_len =~ /^(\d+)-(\d+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 7 | my ($from, $to) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | # file range. gotta be at least as big as bigger number | ||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 7 | ▶ | unless ($len_chunk >= $to) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | die "Backup chunk $dig isn't at least as big as range: got $len_chunk, needing $to\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 7 | my $region = substr($$dataref, $from, $to-$from); | |||||||||||||||||||||||||||||||||||||||||||||
| 322 | 7 | $dataref = \$region; | |||||||||||||||||||||||||||||||||||||||||||||
| 323 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # using the whole chunk, so make sure fetched size matches | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # expected size | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 38 | ▶ | unless ($len_chunk == $enc_len) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | die "Backup chunk $dig isn't of expected length: got $len_chunk, expecting $enc_len\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 45 | my $decrypted_ref = Brackup::Decrypt::decrypt_data($dataref, meta => $self->{_meta}); | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | 45 | print $fh $$decrypted_ref; | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 37 | ▶ | close($fh) or die "Close failed"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 37 | ▶ | if (my $good_dig = $it->{Digest}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 37 | ▶ | die "not capable of verifying digests of from anything but sha1" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | unless $good_dig =~ /^sha1:(.+)/; | ||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 37 | $good_dig = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 37 | ▶ | sysopen(my $readfh, $full, O_RDONLY) or die "Failed to reopen '$full' for verification: $!"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 37 | binmode($readfh); | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | 37 | my $sha1 = Digest::SHA1->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 344 | 37 | $sha1->addfile($readfh); | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | 37 | my $actual_dig = $sha1->hexdigest; | |||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # TODO: support --onerror={continue,prompt}, etc, but for now we just die | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 37 | ▶ | unless ($actual_dig eq $good_dig || $full =~ m!\.brackup-digest\.db\b!) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$actual_dig eq $good_dig or $full =~ /\.brackup-digest\.db\b/
MC/DC0%0/2
$actual_dig eq $good_dig or $full =~ /\.brackup-digest\.db\b/
$actual_dig eq $good_dig
$full =~ /\.brackup-digest\.db\b/
Truth table33%1/3
A or B
A= $actual_dig eq $good_digB= $full =~ /\.brackup-digest\.db\b/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | die "Digest of restored file ($full) doesn't match"; | |||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 37 | $self->_update_statinfo($full, $it); | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # returns iterator subref which returns hashrefs or undef on EOF | ||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 7 | ▶ | sub parser { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parser: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 359 | 7 | return Brackup::Metafile->open($self->{metafile}->name); | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||