Export/Unix.pm

filter: Statementstmt 60.1% 378 / 629 Branchbran 48.2% 196 / 406 Conditioncond 38.6% 126 / 326 MC/DCmcdc 18.5% 36 / 194 Subroutinesub 75.0% 63 / 84 Podpod 100% 35 / 35 totaltotal 49.8% 834 / 1674 CC 337 SCAR 47.8
CC
337
Cov
51%
add
405.5
get_dst_uid_gid
306.0
process_elf_file
272.0
CRAP 119.0
« Export/Linux.pm ↑ Summary Export/CPIO.pm »
1 package Sys::Export::Unix;
2  
3 # ABSTRACT: Export subsets of a UNIX system
4 10 our $VERSION = '0.006'; # VERSION
5  
6  
7 10 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use experimental qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Carp qw( croak carp );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use Cwd qw( abs_path );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Scalar::Util qw( blessed looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use List::Util qw( max );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use Sys::Export qw( :isa :stat_modes :stat_tests map_or_load_file );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶use Sys::Export::LogAny;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 10 require Sys::Export::LazyFileData;
19 10 require Sys::Export::Exporter;
20 10 our @CARP_NOT= qw( Sys::Export );
21 10 our @ISA= qw( Sys::Export::Exporter );
22 10 our $have_unix_mknod= !!eval { require Unix::Mknod; };
23  
24 14 ▶sub new {
Subroutine new: called CC=26 SCAR=39.5
Pod documented
25 14 my $class= shift;
26 0 ▶ my %attrs= @_ == 1 && isa_hash $_[0]? %{$_[0]}
Branch: 2 branches
BranchTrueFalseTotal
@_ == 1 && &isa_hash($_[0]) ? : 0 14 14
!(@_ & 1) ? : 14 0 14
Condition33%1/3
@_ == 1 and &isa_hash($_[0])
!ll&&!rl&&r
1400
MC/DC0%0/2
@_ == 1 and &isa_hash($_[0])
@_ == 1 &isa_hash($_[0])
Truth table33%1/3
A and B
A= @_ == 1B= &isa_hash($_[0])
ABresult
0X0
100
111
27 : !(@_ & 1)? @_
28 : croak "Expected hashref or even-length list";
29  
30 14 ▶ defined $attrs{src} or croak "Require 'src' attribute";
Branch: 1 branch
BranchTrueFalseTotal
defined $attrs{"src"} or croak("Require 'src' attribute") 14 0 14
31 # must end with trailing '/'
32 14 ▶ $attrs{src} .= '/' unless $attrs{src} =~ m{/\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $attrs{"src"} =~ m[/\z]u 10 4 14
33 my $src_abs= abs_path($attrs{src})
34 14 ▶ or croak "src directory '$attrs{src}' does not exist";
Branch: 1 branch
BranchTrueFalseTotal
my $src_abs = abs_path($attrs{"src"}) or croak(qq[src directory '$attrs{"src"}' does not exist]) 14 0 14
35 14 ▶ $src_abs .= '/' unless $src_abs =~ m{/\z};
Branch: 1 branch
BranchTrueFalseTotal
unless $src_abs =~ m[/\z]u 11 3 14
36 14 $attrs{src_abs}= $src_abs;
37  
38 14 ▶ defined $attrs{dst} or croak "Require 'dst' attribute";
Branch: 1 branch
BranchTrueFalseTotal
defined $attrs{"dst"} or croak("Require 'dst' attribute") 14 0 14
39 14 ▶ if (isa_export_dst $attrs{dst}) {
Branch: 2 branches
BranchTrueFalseTotal
if (&isa_export_dst($attrs{'dst'})) { } 7 7 14
elsif (&isa_array($attrs{'dst'})) { } 0 7 7
40 7 $attrs{_dst}= $attrs{dst};
41 } elsif (isa_array $attrs{dst}) {
42 0 my @spec= @{$attrs{dst}};
43 0 my $type= shift @spec;
44 0 ▶ if (uc $type eq 'CPIO') {
Branch: 1 branch
BranchTrueFalseTotal
if (uc $type eq 'CPIO') { } 0 0 0
45 0 require Sys::Export::CPIO;
46 0 $attrs{_dst}= Sys::Export::CPIO->new(@spec);
47 } else {
48 0 croak "Unknown -dst type '$type'";
49 }
50 } else {
51 7 ▶ my $dst_abs= abs_path($attrs{dst} =~ s,(?<=[^/])$,/,r)
Branch: 1 branch
BranchTrueFalseTotal
my $dst_abs = abs_path($attrs{"dst"} =~ s[(?<=[^/])$][/]ru) or croak(qq[dst directory '$attrs{"dst"}' does not exist]) 7 0 7
52 or croak "dst directory '$attrs{dst}' does not exist";
53 7 ▶ length $dst_abs > 1
Branch: 1 branch
BranchTrueFalseTotal
length $dst_abs > 1 or croak("cowardly refusing to export to '${dst_abs}'") 7 0 7
54 or croak "cowardly refusing to export to '$dst_abs'";
55 7 require Sys::Export::Unix::WriteFS;
56 $attrs{_dst}= Sys::Export::Unix::WriteFS->new(
57 dst => $attrs{dst},
58 tmp => $attrs{tmp},
59 on_collision => $attrs{on_collision},
60 7 );
61 }
62 # default tmp dir to whatever dst chose, if it has a preference
63 $attrs{tmp} //= $attrs{_dst}->tmp
64 14 ▶ if $attrs{_dst}->can('tmp');
Branch: 1 branch
BranchTrueFalseTotal
if $attrs{"_dst"}->can("tmp") 7 7 14
Condition33%1/3
$attrs{"tmp"} //= $attrs{"_dst"}->tmp
l!l&&r!l&&!r
070
MC/DC0%0/2
$attrs{"tmp"} //= $attrs{"_dst"}->tmp
$attrs{"tmp"} $attrs{"_dst"}->tmp
Truth table33%1/3
A //= B
A= $attrs{"tmp"}B= $attrs{"_dst"}->tmp
ABresult
1X1
011
000
65 # otherwise use system tmp dir
66 14 ▶ $attrs{tmp} //= File::Temp->newdir;
Condition66%2/3
$attrs{"tmp"} //= "File::Temp"->newdir
l!l&&r!l&&!r
770
MC/DC0%0/2
$attrs{"tmp"} //= "File::Temp"->newdir
$attrs{"tmp"} "File::Temp"->newdir
Truth table66%2/3
A //= B
A= $attrs{"tmp"}B= "File::Temp"->newdir
ABresult
1X1
011
000
67 14 ▶ $attrs{log} //= Sys::Export::LogAny->get_logger;
Condition33%1/3
$attrs{"log"} //= "Sys::Export::LogAny"->get_logger
l!l&&r!l&&!r
0140
MC/DC0%0/2
$attrs{"log"} //= "Sys::Export::LogAny"->get_logger
$attrs{"log"} "Sys::Export::LogAny"->get_logger
Truth table33%1/3
A //= B
A= $attrs{"log"}B= "Sys::Export::LogAny"->get_logger
ABresult
1X1
011
000
68  
69 # Upgrade src_userdb and dst_userdb if provided as hashrefs
70 14 for (qw( src_userdb dst_userdb )) {
71 28 ▶ if (defined $attrs{$_} && !isa_userdb($attrs{$_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $attrs{$_} and not &isa_userdb($attrs{$_})) 1 27 28
Condition66%2/3
defined $attrs{$_} and not &isa_userdb($attrs{$_})
!ll&&!rl&&r
2701
MC/DC50%1/2
defined $attrs{$_} and not &isa_userdb($attrs{$_})
defined $attrs{$_} not &isa_userdb($attrs{$_})
Truth table66%2/3
A and not(B)
A= defined $attrs{$_}B= not &isa_userdb($attrs{$_})
ABresult
0X0
100
111
72 1 require Sys::Export::Unix::UserDB;
73 1 $attrs{$_}= Sys::Export::Unix::UserDB->new($attrs{$_});
74 }
75 }
76  
77 14 my $self= bless \%attrs, $class;
78  
79 # Run the accessor logic to coerce the parameter properly
80 14 for my $method (qw( src_exe_path src_lib_path log )) {
81 42 ▶ $self->$method(delete $self->{$method}) if exists $self->{$method};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$method} 14 28 42
82 }
83 # Special cases - call the method once for each key/value pair
84 14 for my $method (qw( rewrite_path rewrite_user rewrite_group )) {
85 42 ▶ my $r= delete $self->{$method}
Branch: 1 branch
BranchTrueFalseTotal
my $r = delete $self->{$method} or next 0 42 42
86 or next;
87 $self->$method($_ => $r->{$_})
88 0 for keys %$r;
89 }
90 14 return $self;
91 }
92  
93  
94 7 ▶sub src($self) { $self->{src} }
Subroutine src: called CC=1 SCAR=0.0
Pod documented
95 68 ▶sub src_abs($self) { $self->{src_abs} }
Subroutine src_abs: called CC=1 SCAR=0.0
Pod documented
96 4 ▶sub dst($self) { $self->{dst} } # sometimes a path string
Subroutine dst: called CC=1 SCAR=0.0
Pod documented
97 58 ▶sub _dst($self) { $self->{_dst} } # always an object
Subroutine _dst: called CC=1 SCAR=0.0
98 21 ▶sub dst_abs($self) { $self->{_dst}->can('dst_abs')? $self->{_dst}->dst_abs : undef }
Subroutine dst_abs: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_dst'}->can('dst_abs') ? : 21 0 21
99 0 ▶sub tmp($self) { $self->{tmp} }
Subroutine tmp: not called CC=1 SCAR=6.9
Pod documented
100 1 ▶sub src_path_set($self) { $self->{src_path_set} //= {} }
Subroutine src_path_set: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
$self->{"src_path_set"} //= {}
l!l
10
MC/DC0%0/1
$self->{"src_path_set"} //= {}
$self->{"src_path_set"}
Truth table50%1/2
A
A= $self->{"src_path_set"}
Aresult
11
00
101 3 ▶sub dst_path_set($self) { $self->{dst_path_set} //= {} }
Subroutine dst_path_set: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
$self->{"dst_path_set"} //= {}
l!l
30
MC/DC0%0/1
$self->{"dst_path_set"} //= {}
$self->{"dst_path_set"}
Truth table50%1/2
A
A= $self->{"dst_path_set"}
Aresult
11
00
102 1 ▶sub dst_uid_used($self) { $self->{dst_uid_used} //= {} }
Subroutine dst_uid_used: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
$self->{"dst_uid_used"} //= {}
l!l
10
MC/DC0%0/1
$self->{"dst_uid_used"} //= {}
$self->{"dst_uid_used"}
Truth table50%1/2
A
A= $self->{"dst_uid_used"}
Aresult
11
00
103 1 ▶sub dst_gid_used($self) { $self->{dst_gid_used} //= {} }
Subroutine dst_gid_used: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
$self->{"dst_gid_used"} //= {}
l!l
10
MC/DC0%0/1
$self->{"dst_gid_used"} //= {}
$self->{"dst_gid_used"}
Truth table50%1/2
A
A= $self->{"dst_gid_used"}
Aresult
11
00
104 0 ▶sub src_userdb($self) { $self->{src_userdb} }
Subroutine src_userdb: not called CC=1 SCAR=6.9
Pod documented
105 1 ▶sub dst_userdb($self) { $self->{dst_userdb} }
Subroutine dst_userdb: called CC=1 SCAR=0.0
Pod documented
106 166 ▶sub log {
Subroutine log: called CC=4 SCAR=14.6
Pod documented
107 166 ▶ if (@_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 14 152 166
108 14 ▶ croak "Expected Log::Any-compatible object" unless blessed($_[1]) && $_[1]->can('infof');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($_[1]) and $_[1]->can("infof") 0 14 14
Condition33%1/3
builtin::blessed($_[1]) and $_[1]->can("infof")
!ll&&!rl&&r
0014
MC/DC0%0/2
builtin::blessed($_[1]) and $_[1]->can("infof")
builtin::blessed($_[1]) $_[1]->can("infof")
Truth table33%1/3
A and B
A= builtin::blessed($_[1])B= $_[1]->can("infof")
ABresult
0X0
100
111
109 14 $_[0]{log}= $_[1];
110 }
111 166 $_[0]{log};
112 }
113  
114 9 ▶sub _distinct_abs_directories($self, $warn, @list) {
Subroutine _distinct_abs_directories: called CC=6 SCAR=17.9
115 9 for (@list) {
116 54 my $abs= $self->_src_abs_path($_); # resolve symlinks
117 54 ▶ if (defined $abs && -d $self->src_abs . $abs) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $abs and -d $self->src_abs . $abs) { } 27 27 54
Condition66%2/3
defined $abs and -d $self->src_abs . $abs
!ll&&!rl&&r
27027
MC/DC50%1/2
defined $abs and -d $self->src_abs . $abs
defined $abs -d $self->src_abs . $abs
Truth table66%2/3
A and B
A= defined $absB= -d $self->src_abs . $abs
ABresult
0X0
100
111
118 27 $_= $abs;
119 } else {
120 27 ▶ $self->log->warn("No such directory $_") if $warn;
Branch: 1 branch
BranchTrueFalseTotal
if $warn 6 21 27
121 27 $_= undef;
122 }
123 }
124 9 my %seen;
125 9 ▶ return [ grep defined && !$seen{$_}++, @list ]
Condition100%3/3
defined $_ && !$seen{$_}++
!ll&&!rl&&r
27621
MC/DC100%2/2
defined $_ && !$seen{$_}++
defined $_ !$seen{$_}++
Truth table100%3/3
A && not(B)
A= defined $_B= !$seen{$_}++
ABresult
0X0
100
111
126 }
127  
128 2 ▶sub src_exe_path($self, @value) {
Subroutine src_exe_path: called CC=3 SCAR=15.4
Pod documented
129 $self->src_exe_path_list(
130 0 ▶ ref $value[0] eq 'ARRAY'? @{ $value[0] }
Branch: 2 branches
BranchTrueFalseTotal
if @value 0 2 2
ref $value[0] eq 'ARRAY' ? : 0 0 0
131 : map split(/:/, $_, -1), @value
132 ) if @value;
133 2 return join ':', map "/$_", $self->src_exe_path_list;
134 }
135  
136 4 ▶sub src_exe_path_list($self, @value) {
Subroutine src_exe_path_list: called CC=3 SCAR=12.0
Pod documented
137 4 ▶ if (@value) {
Branch: 1 branch
BranchTrueFalseTotal
if (@value) 0 4 4
138 0 $self->{src_exe_path}= $self->_distinct_abs_directories(1, @value);
139 }
140 4 ▶ return @{ $self->{src_exe_path} //= $self->_build_src_exe_path };
Condition66%2/3
$self->{"src_exe_path"} //= $self->_build_src_exe_path
l!l&&r!l&&!r
220
MC/DC0%0/2
$self->{"src_exe_path"} //= $self->_build_src_exe_path
$self->{"src_exe_path"} $self->_build_src_exe_path
Truth table66%2/3
A //= B
A= $self->{"src_exe_path"}B= $self->_build_src_exe_path
ABresult
1X1
011
000
141 }
142  
143 2 ▶sub _build_src_exe_path($self) {
Subroutine _build_src_exe_path: called CC=2 SCAR=6.9
144 2 my @exe_path= qw( usr/local/sbin usr/local/bin usr/sbin usr/bin sbin bin );
145 push @exe_path, grep s{^/}{}, split /:/, $ENV{PATH}
146 2 ▶ if $self->src_abs eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if $self->src_abs eq "/" 1 1 2
147 2 return $self->_distinct_abs_directories(0, @exe_path);
148 }
149  
150 # back-compat
151 10 *src_exe_PATH= *src_exe_path;
152 10 *src_exe_PATH_list= *src_exe_path_list;
153  
154 0 ▶sub src_lib_path($self, @value) {
Subroutine src_lib_path: not called CC=3 SCAR=24.8
Pod documented
155 $self->src_lib_path_list(
156 0 ▶ ref $value[0] eq 'ARRAY'? @{ $value[0] }
Branch: 2 branches
BranchTrueFalseTotal
if @value 0 0 0
ref $value[0] eq 'ARRAY' ? : 0 0 0
157 : map split(/:/, $_, -1), @value
158 ) if @value;
159 0 return join ':', map "/$_", $self->src_lib_path_list;
160 }
161  
162 4 ▶sub src_lib_path_list($self, @value) {
Subroutine src_lib_path_list: called CC=3 SCAR=13.3
Pod documented
163 4 ▶ if (@value) {
Branch: 1 branch
BranchTrueFalseTotal
if (@value) 0 4 4
164 0 $self->{src_lib_path}= $self->_distinct_abs_directories(1, @value);
165 }
166 4 ▶ return @{ $self->{src_lib_path} //= $self->_build_src_lib_path };
Condition33%1/3
$self->{"src_lib_path"} //= $self->_build_src_lib_path
l!l&&r!l&&!r
040
MC/DC0%0/2
$self->{"src_lib_path"} //= $self->_build_src_lib_path
$self->{"src_lib_path"} $self->_build_src_lib_path
Truth table33%1/3
A //= B
A= $self->{"src_lib_path"}B= $self->_build_src_lib_path
ABresult
1X1
011
000
167 }
168  
169 4 ▶sub _build_src_lib_path($self) {
Subroutine _build_src_lib_path: called CC=1 SCAR=0.0
170 4 return $self->_distinct_abs_directories(0,
171 qw( usr/local/lib64 usr/local/lib usr/lib64 usr/lib lib64 lib )
172 );
173 }
174  
175 #=attribute _can_run_in_src
176 #
177 #This is a boolean that indicates whether executables in the source directory can be executed
178 #on this host. This is always true if "src" is '/', since perl wouldn't be able to run in this
179 #environment to run Sys::Export if that weren't true. If src is any other path, this module
180 #needs 'chroot' permission, and tests using C<< chroot $srcdir /bin/sh -c 'exit 0' >>.
181 #
182 #=cut
183  
184 1 ▶sub _can_run_in_src($self) {
Subroutine _can_run_in_src: called CC=3 SCAR=17.3
185 0 ▶ $self->{can_run_in_src} //= ($self->src_abs eq '/' or eval { $self->_run_in_src('sh','-c','exit 0'); 1 });
Condition33%2/6
$self->{"can_run_in_src"} //= $self->src_abs eq "/" || eval { do { $self->_run_in_src("sh", "-c", "exit 0"); 1 } }
l!l&&r!l&&!r
010
$self->src_abs eq '/' || eval { do { $self->_run_in_src('sh', '-c', 'exit 0'); 1 } }
l!l&&r!l&&!r
100
MC/DC0%0/3
$self->{"can_run_in_src"} //= $self->src_abs eq "/" || eval { do { $self->_run_in_src("sh", "-c", "exit 0"); 1 } }
$self->{"can_run_in_src"} $self->src_abs eq '/' eval { do { $self->_run_in_src('sh', '-c', 'exit 0'); 1 } }
Truth table0%0/4
A //= B || C
A= $self->{"can_run_in_src"}B= $self->src_abs eq '/'C= eval { do { $self->_run_in_src('sh', '-c', 'exit 0'); 1 } }
ABCresult
1XX1
01X1
0011
0000
186 }
187 0 ▶sub _run_in_src($self, $cmd, @args) {
Subroutine _run_in_src: not called CC=12 SCAR=50.5
188 0 my $src_abs= $self->src_abs;
189 0 ▶ if ($cmd !~ m,/, && !-x $src_abs . $cmd) { # not an absolute path
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd =~ m[/]u or -x $src_abs . $cmd) 0 0 0
Condition0%0/3
$cmd =~ m[/]u or -x $src_abs . $cmd
l!l&&r!l&&!r
000
MC/DC0%0/2
$cmd =~ m[/]u or -x $src_abs . $cmd
$cmd =~ m[/]u -x $src_abs . $cmd
Truth table0%0/3
A or B
A= $cmd =~ m[/]uB= -x $src_abs . $cmd
ABresult
1X1
011
000
190 0 ▶ my $path= $self->src_which($cmd)
Condition0%0/2
$self->src_which($cmd) // croak("Can't locate '${cmd}' under $src_abs in PATH=" . $self->src_exe_PATH)
l!l
00
MC/DC0%0/1
$self->src_which($cmd) // croak("Can't locate '${cmd}' under $src_abs in PATH=" . $self->src_exe_PATH)
$self->src_which($cmd)
Truth table0%0/2
A
A= $self->src_which($cmd)
Aresult
11
00
191 // croak "Can't locate '$cmd' under $src_abs in PATH=".$self->src_exe_PATH;
192 0 $cmd= $path;
193 }
194 0 ▶ pipe(my $err_r, my $err_w) // croak "pipe: $!";
Condition0%0/2
pipe(my $err_r, my $err_w) // croak("pipe: $!")
l!l
00
MC/DC0%0/1
pipe(my $err_r, my $err_w) // croak("pipe: $!")
pipe(my $err_r, my $err_w)
Truth table0%0/2
A
A= pipe(my $err_r, my $err_w)
Aresult
11
00
195 0 ▶ my $pid= fork() // croak "fork: $!";
Condition0%0/2
fork // croak("fork: $!")
l!l
00
MC/DC0%0/1
fork // croak("fork: $!")
fork
Truth table0%0/2
A
A= fork
Aresult
11
00
196 0 ▶ if (!$pid) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $pid) { } 0 0 0
197 0 eval {
198 0 ▶ if ($src_abs ne '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($src_abs ne "/") 0 0 0
199 0 ▶ chdir $src_abs // die "chdir($src_abs): $!";
Condition0%0/2
chdir $src_abs // die("chdir($src_abs): $!")
l!l
00
MC/DC0%0/1
chdir $src_abs // die("chdir($src_abs): $!")
chdir $src_abs
Truth table0%0/2
A
A= chdir $src_abs
Aresult
11
00
200 0 ▶ chroot $src_abs // die "chroot($src_abs): $!";
Condition0%0/2
chroot $src_abs // die("chroot($src_abs): $!")
l!l
00
MC/DC0%0/1
chroot $src_abs // die("chroot($src_abs): $!")
chroot $src_abs
Truth table0%0/2
A
A= chroot $src_abs
Aresult
11
00
201 }
202 0 ▶ exec($cmd, @args) // die "exec: $!";
Condition0%0/2
exec($cmd, @args) // die("exec: $!")
l!l
00
MC/DC0%0/1
exec($cmd, @args) // die("exec: $!")
exec($cmd, @args)
Truth table0%0/2
A
A= exec($cmd, @args)
Aresult
11
00
203 };
204 0 $err_w->print($@);
205 0 $err_w->close;
206 0 POSIX::_exit(1);
207 }
208 else {
209 0 local $/;
210 0 my $err= <$err_r>;
211 0 ▶ if (length $err) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $err) 0 0 0
212 0 waitpid($pid, 0);
213 0 die $err;
214 }
215 # else command is running
216 0 waitpid($pid, 0);
217 0 return $?;
218 }
219 }
220  
221  
222 29 ▶sub path_rewrite_regex($self) {
Subroutine path_rewrite_regex: called CC=4 SCAR=13.9
Pod documented
223 29 ▶ $self->{path_rewrite_regex} //= do {
Condition66%2/3
$self->{"path_rewrite_regex"} //= do { my $rw = $self->{"path_rewrite_map"} // {}; !keys(%$rw) ? qr/(*FAIL)/u : qr/(@{[join("|", map(quotemeta($_), reverse sort(keys %$rw)))];})/u }
l!l&&r!l&&!r
2540
MC/DC0%0/2
$self->{"path_rewrite_regex"} //= do { my $rw = $self->{"path_rewrite_map"} // {}; !keys(%$rw) ? qr/(*FAIL)/u : qr/(@{[join("|", map(quotemeta($_), reverse sort(keys %$rw)))];})/u }
$self->{"path_rewrite_regex"} do { my $rw = $self->{"path_rewrite_map"} // {}; !keys(%$rw) ? qr/(*FAIL)/u : qr/(@{[join("|", map(quotemeta($_), reverse sort(keys %$rw)))];})/u }
Truth table66%2/3
A //= B
A= $self->{"path_rewrite_regex"}B= do { my $rw = $self->{"path_rewrite_map"} // {}; !keys(%$rw) ? qr/(*FAIL)/u : qr/(@{[join("|", map(quotemeta($_), reverse sort(keys %$rw)))];})/u }
ABresult
1X1
011
000
224 4 ▶ my $rw= $self->{path_rewrite_map} // {};
Condition100%2/2
$self->{"path_rewrite_map"} // {}
l!l
13
MC/DC100%1/1
$self->{"path_rewrite_map"} // {}
$self->{"path_rewrite_map"}
Truth table100%2/2
A
A= $self->{"path_rewrite_map"}
Aresult
11
00
225 4 ▶ !keys %$rw? qr/(*FAIL)/
Branch: 1 branch
BranchTrueFalseTotal
!keys(%$rw) ? : 3 1 4
226 1 : qr/(@{[ join '|', map quotemeta, reverse sort keys %$rw ]})/;
227 };
228 }
229  
230 # a hashref tracking files with link-count higher than 1, so that hardlinks can be preserved.
231 # the keys are "$dev:$ino"
232 2 ▶sub _link_map($self) { $self->{link_map} //= {} }
Subroutine _link_map: called CC=2 SCAR=6.9
Condition100%2/2
$self->{"link_map"} //= {}
l!l
11
MC/DC100%1/1
$self->{"link_map"} //= {}
$self->{"link_map"}
Truth table100%2/2
A
A= $self->{"link_map"}
Aresult
11
00
233  
234 # a hashref listing all the interpreters that have been discovered for programs
235 # and scripts copied to dst. The keys are the relative source path.
236 0 ▶sub _elf_interpreters($self) { $self->{elf_interpreters} //= {} }
Subroutine _elf_interpreters: not called CC=2 SCAR=17.9
Condition0%0/2
$self->{"elf_interpreters"} //= {}
l!l
00
MC/DC0%0/1
$self->{"elf_interpreters"} //= {}
$self->{"elf_interpreters"}
Truth table0%0/2
A
A= $self->{"elf_interpreters"}
Aresult
11
00
237  
238 # Can we use strace (or similar) on binaries in src to see all files they touch?
239 1 ▶sub _can_trace_deps($self) {
Subroutine _can_trace_deps: called CC=4 SCAR=16.4
240 1 ▶ $self->{_can_trace_deps} //= do {
Condition33%1/3
$self->{"_can_trace_deps"} //= do { eval { do { $self->{"_trace_deps"} //= $self->_build__trace_deps } } or $self->log->debug("Error building _trace_deps function: $@"); not !$self->{"_trace_deps"} }
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"_can_trace_deps"} //= do { eval { do { $self->{"_trace_deps"} //= $self->_build__trace_deps } } or $self->log->debug("Error building _trace_deps function: $@"); not !$self->{"_trace_deps"} }
$self->{"_can_trace_deps"} do { eval { do { $self->{"_trace_deps"} //= $self->_build__trace_deps } } or $self->log->debug("Error building _trace_deps function: $@"); not !$self->{"_trace_deps"} }
Truth table33%1/3
A //= B
A= $self->{"_can_trace_deps"}B= do { eval { do { $self->{"_trace_deps"} //= $self->_build__trace_deps } } or $self->log->debug("Error building _trace_deps function: $@"); not !$self->{"_trace_deps"} }
ABresult
1X1
011
000
241 1 ▶ eval { $self->{_trace_deps} //= $self->_build__trace_deps }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->{"_trace_deps"} //= $self->_build__trace_deps } } or $self->log->debug("Error building _trace_deps function: $@") 0 1 1
Condition33%1/3
$self->{"_trace_deps"} //= $self->_build__trace_deps
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{"_trace_deps"} //= $self->_build__trace_deps
$self->{"_trace_deps"} $self->_build__trace_deps
Truth table33%1/3
A //= B
A= $self->{"_trace_deps"}B= $self->_build__trace_deps
ABresult
1X1
011
000
242 or $self->log->debug("Error building _trace_deps function: $@");
243 1 !!$self->{_trace_deps};
244 };
245 }
246  
247 0 ▶sub _trace_deps($self, @argv) {
Subroutine _trace_deps: not called CC=2 SCAR=17.9
248 0 ▶ ($self->{_trace_deps} //= $self->_build__trace_deps)->($self, @argv);
Condition0%0/3
$self->{"_trace_deps"} //= $self->_build__trace_deps
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"_trace_deps"} //= $self->_build__trace_deps
$self->{"_trace_deps"} $self->_build__trace_deps
Truth table0%0/3
A //= B
A= $self->{"_trace_deps"}B= $self->_build__trace_deps
ABresult
1X1
011
000
249 }
250  
251 0 ▶sub _build__trace_deps {
Subroutine _build__trace_deps: not called CC=1 SCAR=6.9
252 # ::Linux subclass overrides this, for strace support.
253 0 croak "No options available for tracing runtime dependencies";
254 }
255  
256 13 ▶sub DESTROY($self, @) {
Subroutine DESTROY: called CC=2 SCAR=7.6
257 13 ▶ $self->finish if $self->{_delayed_apply_stat};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_delayed_apply_stat"} 0 13 13
258 }
259  
260  
261 0 ▶sub on_collision($self, @value) {
Subroutine on_collision: not called CC=2 SCAR=17.9
Pod documented
262 0 ▶ $self->{on_collision}= $value[0] if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 0 0 0
263 $self->{on_collision}
264 0 }
265  
266 36 ▶sub _log_action($self, $verb, $src, $dst, @notes) {
Subroutine _log_action: called CC=5 SCAR=30.3
267 36 ▶ if ($self->log->is_info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->log->is_info) 0 36 36
268 # Track the width of the previous 10 filenames to provide easy-to-read consistent indenting
269 0 ▶ my $widths= ($self->{_log_name_widths} //= []);
Condition0%0/2
$self->{"_log_name_widths"} //= []
l!l
00
MC/DC0%0/1
$self->{"_log_name_widths"} //= []
$self->{"_log_name_widths"}
Truth table0%0/2
A
A= $self->{"_log_name_widths"}
Aresult
11
00
270 0 unshift @$widths, length($src);
271 0 ▶ pop @$widths if @$widths > 10;
Branch: 1 branch
BranchTrueFalseTotal
if @$widths > 10 0 0 0
272 0 my $width= max(24, @$widths);
273 # Then round width to a multiple of 8
274 0 $width= ($width + 7) & ~7;
275 0 $self->log->infof("%3s %-*s -> %s", $verb, $width, $src, $dst);
276 0 $self->log->infof(" %s", $_) for @notes;
277 }
278 }
279  
280  
281 2 ▶sub rewrite_path($self, $orig, $new) {
Subroutine rewrite_path: called CC=6 SCAR=19.4
Pod documented
282 2 ▶ my $rw= ($self->{path_rewrite_map} //= {});
Condition100%2/2
$self->{"path_rewrite_map"} //= {}
l!l
11
MC/DC100%1/1
$self->{"path_rewrite_map"} //= {}
$self->{"path_rewrite_map"}
Truth table100%2/2
A
A= $self->{"path_rewrite_map"}
Aresult
11
00
283 2 $orig =~ s,^/,,;
284 2 $new =~ s,^/,,;
285 2 ▶ $orig !~ m,^[.]+/, && $new !~ m,^[.]+/,
Branch: 1 branch
BranchTrueFalseTotal
$orig =~ m[^[.]+/]u || $new =~ m[^[.]+/]u and croak("Paths for rewrite_path must be logically absolute ($orig => $new)") 0 2 2
Condition33%1/3
$orig =~ m[^[.]+/]u or $new =~ m[^[.]+/]u
l!l&&r!l&&!r
002
MC/DC0%0/2
$orig =~ m[^[.]+/]u or $new =~ m[^[.]+/]u
$orig =~ m[^[.]+/]u $new =~ m[^[.]+/]u
Truth table33%1/3
A or B
A= $orig =~ m[^[.]+/]uB= $new =~ m[^[.]+/]u
ABresult
1X1
011
000
286 or croak "Paths for rewrite_path must be logically absolute ($orig => $new)";
287 croak "Conflicting rewrite supplied for '$orig'"
288 2 ▶ if exists $rw->{$orig} && $rw->{$orig} ne $new;
Branch: 1 branch
BranchTrueFalseTotal
if exists $rw->{$orig} and $rw->{$orig} ne $new 0 2 2
Condition33%1/3
exists $rw->{$orig} and $rw->{$orig} ne $new
!ll&&!rl&&r
200
MC/DC0%0/2
exists $rw->{$orig} and $rw->{$orig} ne $new
exists $rw->{$orig} $rw->{$orig} ne $new
Truth table33%1/3
A and B
A= exists $rw->{$orig}B= $rw->{$orig} ne $new
ABresult
0X0
100
111
289 2 $rw->{$orig}= $new;
290 2 delete $self->{path_rewrite_regex}; # lazy-built
291 2 $self;
292 }
293  
294 19 ▶sub _has_rewrites($self) {
Subroutine _has_rewrites: called CC=2 SCAR=6.9
295 19 ▶ $self->{path_rewrite_map} && %{$self->{path_rewrite_map}}
Branch: 1 branch
BranchTrueFalseTotal
$self->{"path_rewrite_map"} and %{$self->{"path_rewrite_map"};} 9 10 19
296 }
297  
298 # Resolve symlinks in paths within $root/ treating absolute links as references to $root.
299 # This returns undef if:
300 # * the path doesn't exist at any point during resolution
301 # * 'stat' fails at any point in the path (maybe for permissions)
302 # * it resolves more than 256 symlinks
303 # * readlink fails
304 # Un-intuitively, this returns a string without a leading '/' because that's what I need below.
305 88 ▶sub _chroot_abs_path($self, $root, $path) {
Subroutine _chroot_abs_path: called CC=14 SCAR=26.6
306 88 ▶ my @base= $root eq '/'? ('') : split '/', $root;
Branch: 1 branch
BranchTrueFalseTotal
$root eq '/' ? : 9 79 88
307 88 my @abs= @base;
308 88 ▶ my @parts= grep length && $_ ne '.', split '/', $path;
Condition100%3/3
length $_ && $_ ne '.'
!ll&&!rl&&r
11209
MC/DC100%2/2
length $_ && $_ ne '.'
length $_ $_ ne '.'
Truth table100%3/3
A && B
A= length $_B= $_ ne '.'
ABresult
0X0
100
111
309 88 my $lim= 256;
310 88 ▶ while (@parts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parts) 222 60 282
311 222 my $part= shift @parts;
312 222 my $abs= join '/', @abs, $part;
313 222 ▶ my (undef, undef, $mode)= lstat $abs
Branch: 1 branch
BranchTrueFalseTotal
my(undef, undef, $mode) = lstat $abs or return undef 194 28 222
314 or return undef;
315 194 ▶ if ($part eq '..') {
Branch: 2 branches
BranchTrueFalseTotal
if ($part eq '..') { } 6 188 194
elsif (S_ISLNK($mode)) { } 18 170 188
316 # In Linux at least, ".." from root directory loops back to itself
317 6 ▶ pop @abs if @abs > @base;
Branch: 1 branch
BranchTrueFalseTotal
if @abs > @base 6 0 6
318 }
319 elsif (S_ISLNK($mode)) {
320 18 ▶ return undef if --$lim <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$lim <= 0 0 18 18
321 18 ▶ defined (my $newpath= readlink $abs) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined(my $newpath = readlink $abs) or return undef 18 0 18
322 18 ▶ $newpath =~ s{\\}{/}g if $^O eq 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O eq "MSWin32" 0 18 18
323 18 ▶ @abs= @base if $newpath =~ m,^/,;
Branch: 1 branch
BranchTrueFalseTotal
if $newpath =~ m[^/]u 11 7 18
324 18 ▶ unshift @parts, grep length && $_ ne '.', split '/', $newpath;
Condition66%2/3
length $_ && $_ ne '.'
!ll&&!rl&&r
11029
MC/DC50%1/2
length $_ && $_ ne '.'
length $_ $_ ne '.'
Truth table66%2/3
A && B
A= length $_B= $_ ne '.'
ABresult
0X0
100
111
325 }
326 else {
327 170 push @abs, $part;
328 }
329 }
330 60 my $abs= join '/', @abs[scalar @base .. $#abs];
331 60 ▶ $self->log->tracef("Absolute path of '%s' within root '%s' is '%s'", $path, $root, $abs)
Branch: 1 branch
BranchTrueFalseTotal
if $abs ne $path 14 46 60
332 if $abs ne $path;
333 60 return $abs;
334 }
335  
336 88 ▶sub _src_abs_path($self, $path) {
Subroutine _src_abs_path: called CC=1 SCAR=0.0
337 88 $self->_chroot_abs_path($self->{src_abs}, $path);
338 }
339  
340 # Like src_abs_path, this performs a logical abs_path on all path components *except* the final
341 # one, so the parent directories will be resolved to an absolute path, but the leaf directory
342 # entry is not resolved and doesn't even need to exist.
343 33 ▶sub _src_parent_abs_path($self, $path) {
Subroutine _src_parent_abs_path: called CC=5 SCAR=16.7
344 # Determine the final path component, ignoring '.'
345 33 ▶ my @path= grep length && $_ ne '.', split '/', $path;
Condition66%2/3
length $_ && $_ ne '.'
!ll&&!rl&&r
6085
MC/DC50%1/2
length $_ && $_ ne '.'
length $_ $_ ne '.'
Truth table66%2/3
A && B
A= length $_B= $_ ne '.'
ABresult
0X0
100
111
346 33 ▶ return $path[0] // '' unless @path > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @path > 1 9 24 33
Condition50%1/2
$path[0] // ""
l!l
90
MC/DC0%0/1
$path[0] // ""
$path[0]
Truth table50%1/2
A
A= $path[0]
Aresult
11
00
347 24 my $parent= $self->_src_abs_path(join '/', @path[0 .. $#path - 1]);
348 24 ▶ return defined $parent? "$parent/$path[-1]" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $parent ? : 24 0 24
349 }
350  
351  
352 0 ▶sub rewrite_user($self, $src, $dst) {
Subroutine rewrite_user: not called CC=8 SCAR=42.8
Pod documented
353 croak "A rewrite already exists for $src"
354 0 ▶ if $self->{_user_rewrite_map}{$src};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_user_rewrite_map"}{$src} 0 0 0
355  
356 0 ▶ if (!isa_int($dst)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&isa_int($dst)) 0 0 0
357 0 ▶ my $dst_userdb= ($self->{dst_userdb} //= $self->_build_dst_userdb);
Condition0%0/3
$self->{"dst_userdb"} //= $self->_build_dst_userdb
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"dst_userdb"} //= $self->_build_dst_userdb
$self->{"dst_userdb"} $self->_build_dst_userdb
Truth table0%0/3
A //= B
A= $self->{"dst_userdb"}B= $self->_build_dst_userdb
ABresult
1X1
011
000
358 0 ▶ my $u= $dst_userdb->user($dst)
Branch: 1 branch
BranchTrueFalseTotal
my $u = $dst_userdb->user($dst) or croak("No user '${dst}' in dst_userdb") 0 0 0
359 or croak "No user '$dst' in dst_userdb";
360 0 $dst= $u->uid;
361 }
362 0 ▶ if (!isa_int($src)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&isa_int($src)) 0 0 0
363 # The name must exist in src userdb
364 0 ▶ my $src_userdb= ($self->{src_userdb} //= $self->_build_src_userdb);
Condition0%0/3
$self->{"src_userdb"} //= $self->_build_src_userdb
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"src_userdb"} //= $self->_build_src_userdb
$self->{"src_userdb"} $self->_build_src_userdb
Truth table0%0/3
A //= B
A= $self->{"src_userdb"}B= $self->_build_src_userdb
ABresult
1X1
011
000
365 0 ▶ my $u= $src_userdb->user($src)
Branch: 1 branch
BranchTrueFalseTotal
my $u = $src_userdb->user($src) or croak("No user '${src}' in src_userdb") 0 0 0
366 or croak "No user '$src' in src_userdb";
367 0 $self->{_user_rewrite_map}{$src}= $dst;
368 0 $src= $u->uid;
369 }
370 0 $self->{_user_rewrite_map}{$src}= $dst;
371 }
372  
373 0 ▶sub rewrite_group($self, $src, $dst) {
Subroutine rewrite_group: not called CC=8 SCAR=42.8
Pod documented
374 croak "A rewrite already exists for $src"
375 0 ▶ if $self->{_group_rewrite_map}{$src};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_group_rewrite_map"}{$src} 0 0 0
376  
377 0 ▶ if (!isa_int($dst)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&isa_int($dst)) 0 0 0
378 0 ▶ my $dst_userdb= ($self->{dst_userdb} //= $self->_build_dst_userdb);
Condition0%0/3
$self->{"dst_userdb"} //= $self->_build_dst_userdb
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"dst_userdb"} //= $self->_build_dst_userdb
$self->{"dst_userdb"} $self->_build_dst_userdb
Truth table0%0/3
A //= B
A= $self->{"dst_userdb"}B= $self->_build_dst_userdb
ABresult
1X1
011
000
379 0 ▶ my $g= $dst_userdb->group($dst)
Branch: 1 branch
BranchTrueFalseTotal
my $g = $dst_userdb->group($dst) or croak("No group '${dst}' in dst_userdb") 0 0 0
380 or croak "No group '$dst' in dst_userdb";
381 0 $dst= $g->gid;
382 }
383 0 ▶ if (!isa_int($src)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&isa_int($src)) 0 0 0
384 # The name must exist in src userdb
385 0 ▶ my $src_userdb= ($self->{src_userdb} //= $self->_build_src_userdb);
Condition0%0/3
$self->{"src_userdb"} //= $self->_build_src_userdb
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"src_userdb"} //= $self->_build_src_userdb
$self->{"src_userdb"} $self->_build_src_userdb
Truth table0%0/3
A //= B
A= $self->{"src_userdb"}B= $self->_build_src_userdb
ABresult
1X1
011
000
386 0 ▶ my $g= $src_userdb->group($src)
Branch: 1 branch
BranchTrueFalseTotal
my $g = $src_userdb->group($src) or croak("No group '${src}' in src_userdb") 0 0 0
387 or croak "No group '$src' in src_userdb";
388 0 $self->{_group_rewrite_map}{$src}= $dst;
389 0 $src= $g->gid;
390 }
391 0 $self->{_group_rewrite_map}{$src}= $dst;
392 }
393  
394 0 ▶sub _build_src_userdb($self) {
Subroutine _build_src_userdb: not called CC=2 SCAR=17.9
395 # The default source UserDB pulls from src/etc/passwd and auto_imports users from the host
396 0 require Sys::Export::Unix::UserDB;
397 0 my $udb= Sys::Export::Unix::UserDB->new(auto_import => 1);
398 0 ▶ $udb->load($self->src_abs . 'etc')
Branch: 1 branch
BranchTrueFalseTotal
if -f $self->src_abs . 'etc/passwd' 0 0 0
399 if -f $self->src_abs . 'etc/passwd';
400 0 $udb;
401 }
402  
403 1 ▶sub _build_dst_userdb($self) {
Subroutine _build_dst_userdb: called CC=6 SCAR=20.9
404 # The default dest UserDB uses any dst/etc/passwd and auto_imports users from src_userdb
405 1 require Sys::Export::Unix::UserDB;
406 my $udb= Sys::Export::Unix::UserDB->new(
407 1 ▶ auto_import => ($self->{src_userdb} //= $self->_build_src_userdb)
Condition33%1/3
$self->{"src_userdb"} //= $self->_build_src_userdb
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{"src_userdb"} //= $self->_build_src_userdb
$self->{"src_userdb"} $self->_build_src_userdb
Truth table33%1/3
A //= B
A= $self->{"src_userdb"}B= $self->_build_src_userdb
ABresult
1X1
011
000
408 );
409 1 ▶ $udb->load($self->_dst->dst_abs . 'etc')
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->_dst->can("dst_abs") and -f $self->_dst->dst_abs . 'etc/passwd' 0 1 1
Condition33%1/3
defined $self->_dst->can("dst_abs") and -f $self->_dst->dst_abs . 'etc/passwd'
!ll&&!rl&&r
100
MC/DC0%0/2
defined $self->_dst->can("dst_abs") and -f $self->_dst->dst_abs . 'etc/passwd'
defined $self->_dst->can("dst_abs") -f $self->_dst->dst_abs . 'etc/passwd'
Truth table33%1/3
A and B
A= defined $self->_dst->can("dst_abs")B= -f $self->_dst->dst_abs . 'etc/passwd'
ABresult
0X0
100
111
410 if defined $self->_dst->can('dst_abs') && -f $self->_dst->dst_abs . 'etc/passwd';
411 # make sure the rewrite hashes exist, used as a flag that rerites need to occur.
412 1 ▶ $self->{_user_rewrite_map} //= {};
Condition50%1/2
$self->{"_user_rewrite_map"} //= {}
l!l
01
MC/DC0%0/1
$self->{"_user_rewrite_map"} //= {}
$self->{"_user_rewrite_map"}
Truth table50%1/2
A
A= $self->{"_user_rewrite_map"}
Aresult
11
00
413 1 ▶ $self->{_group_rewrite_map} //= {};
Condition50%1/2
$self->{"_group_rewrite_map"} //= {}
l!l
01
MC/DC0%0/1
$self->{"_group_rewrite_map"} //= {}
$self->{"_group_rewrite_map"}
Truth table50%1/2
A
A= $self->{"_group_rewrite_map"}
Aresult
11
00
414 1 $udb;
415 }
416  
417  
418 28 ▶sub add {
Subroutine add: called CC=80 SCAR=60.1
Pod documented
419 28 my $self= shift;
420 # If called recursively, append to TODO list instead of immediately adding
421 28 ▶ if (ref $self->{add}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"add"}) 6 22 28
422 6 push @{ $self->{add} }, @_;
423 6 return $self;
424 }
425 22 my @add= @_;
426 22 local $self->{add}= \@add;
427 22 my $dst_userdb;
428 22 ▶ while (@add) {
Branch: 1 branch
BranchTrueFalseTotal
if (@add) 51 22 73
429 51 my $next= shift @add;
430 51 my %file;
431 51 ▶ if (isa_hash $next) {
Branch: 2 branches
BranchTrueFalseTotal
if (&isa_hash($next)) { } 15 36 51
elsif (&isa_array($next)) { } 9 27 36
432 15 %file= %$next;
433 } elsif (isa_array $next) {
434 9 %file= Sys::Export::expand_stat_shorthand(@$next);
435 } else {
436 27 %file= ( src_path => $next );
437 }
438 51 ▶ $self->log->debug("Exporting".(defined $file{src_path}? " $file{src_path}" : '').(defined $file{name}? " to $file{name}":''))
Branch: 3 branches
BranchTrueFalseTotal
if $self->log->is_debug 0 51 51
defined $file{'src_path'} ? : 0 0 0
defined $file{'name'} ? : 0 0 0
439 if $self->log->is_debug;
440 # Need to abs-path the parent dir of this path in case src_path follows
441 # symlinks through absolute paths, e.g. "/usr/bin/mount", if /usr/bin is a symlink to
442 # "/bin" rather than "../bin" it will fail whenever ->src is not pointed to '/'.
443 $file{real_src_path} //= $self->_src_parent_abs_path($file{src_path})
444 51 ▶ if defined $file{src_path};
Branch: 1 branch
BranchTrueFalseTotal
if defined $file{"src_path"} 35 16 51
Condition66%2/3
$file{"real_src_path"} //= $self->_src_parent_abs_path($file{"src_path"})
l!l&&r!l&&!r
8270
MC/DC0%0/2
$file{"real_src_path"} //= $self->_src_parent_abs_path($file{"src_path"})
$file{"real_src_path"} $self->_src_parent_abs_path($file{"src_path"})
Truth table66%2/3
A //= B
A= $file{"real_src_path"}B= $self->_src_parent_abs_path($file{"src_path"})
ABresult
1X1
011
000
445 # Translate src to dst if user didn't supply a 'name'
446 51 ▶ if (!defined $file{name} || !defined $file{mode}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file{"name"} and defined $file{"mode"}) 27 24 51
Condition66%2/3
defined $file{"name"} and defined $file{"mode"}
!ll&&!rl&&r
27024
MC/DC50%1/2
defined $file{"name"} and defined $file{"mode"}
defined $file{"name"} defined $file{"mode"}
Truth table66%2/3
A and B
A= defined $file{"name"}B= defined $file{"mode"}
ABresult
0X0
100
111
447 27 my $src_path= $file{src_path};
448 27 ▶ defined $src_path or croak(!defined $file{mode}? "Require src_path to determine 'mode'" : "Require 'name' (or 'src_path' to derive name)");
Branch: 2 branches
BranchTrueFalseTotal
defined $src_path or croak(!defined($file{"mode"}) ? "Require src_path to determine 'mode'" : "Require 'name' (or 'src_path' to derive name)") 27 0 27
!defined($file{'mode'}) ? : 0 0 0
449 # ignore repeat requests
450 27 ▶ if (exists $self->{src_path_set}{$src_path} && !defined $file{name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"src_path_set"}{$src_path} and not defined $file{"name"}) 1 26 27
Condition66%2/3
exists $self->{"src_path_set"}{$src_path} and not defined $file{"name"}
!ll&&!rl&&r
2601
MC/DC50%1/2
exists $self->{"src_path_set"}{$src_path} and not defined $file{"name"}
exists $self->{"src_path_set"}{$src_path} not defined $file{"name"}
Truth table66%2/3
A and not(B)
A= exists $self->{"src_path_set"}{$src_path}B= not defined $file{"name"}
ABresult
0X0
100
111
451 1 $self->log->debugf(" (already exported '%s')", $src_path);
452 1 next;
453 }
454 26 my $real_src_path= $file{real_src_path};
455 26 ▶ if (!defined $real_src_path) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $real_src_path) { } 0 26 26
elsif ($real_src_path ne $src_path) { } 5 21 26
456 0 croak "No such path $src_path";
457 } elsif ($real_src_path ne $src_path) {
458 5 $self->log->debugf("Resolved to '%s'", $real_src_path);
459 # ignore repeat requests
460 5 ▶ if (exists $self->{src_path_set}{$real_src_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"src_path_set"}{$real_src_path}) 3 2 5
461 3 $self->{src_path_set}{$src_path}= $self->{src_path_set}{$real_src_path};
462 3 $self->log->debugf(" (already exported '%s')", $real_src_path);
463 3 next;
464 }
465 }
466 # If mode wasn't supplied, get it from src filesystem
467 23 ▶ if (!defined $file{mode}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file{"mode"}) 23 0 23
468 23 my %stat;
469 23 ▶ @stat{qw( dev ino mode nlink uid gid rdev size atime mtime ctime )}= lstat($self->{src_abs}.$real_src_path)
Branch: 1 branch
BranchTrueFalseTotal
@stat{"dev", "ino", "mode", "nlink", "uid", "gid", "rdev", "size", "atime", "mtime", "ctime"} = lstat $self->{"src_abs"} . $real_src_path or croak(qq[lstat '$self->{"src_abs"}${real_src_path}': $!]) 23 0 23
470 or croak "lstat '$self->{src_abs}$real_src_path': $!";
471 23 %file= ( %stat, %file );
472 }
473  
474 23 ▶ if (defined $file{uid} || defined $file{gid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file{"uid"} or defined $file{"gid"}) 23 0 23
Condition33%1/3
defined $file{"uid"} or defined $file{"gid"}
l!l&&r!l&&!r
2300
MC/DC0%0/2
defined $file{"uid"} or defined $file{"gid"}
defined $file{"uid"} defined $file{"gid"}
Truth table33%1/3
A or B
A= defined $file{"uid"}B= defined $file{"gid"}
ABresult
1X1
011
000
475 # Remap the UID/GID if that feature was requested
476 @file{'uid','gid'}= $self->get_dst_uid_gid($file{uid}//0, $file{gid}//0, " in source filesystem at '$src_path'")
477 23 ▶ if $self->{_user_rewrite_map} || $self->{_group_rewrite_map};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_user_rewrite_map"} or $self->{"_group_rewrite_map"} 0 23 23
Condition14%1/7
$self->{"_user_rewrite_map"} or $self->{"_group_rewrite_map"}
l!l&&r!l&&!r
0023
$file{"uid"} // 0
l!l
00
$file{"gid"} // 0
l!l
00
MC/DC0%0/2
$self->{"_user_rewrite_map"} or $self->{"_group_rewrite_map"}
$self->{"_user_rewrite_map"} $self->{"_group_rewrite_map"}
MC/DC0%0/1
$file{"uid"} // 0
$file{"uid"}
MC/DC0%0/1
$file{"gid"} // 0
$file{"gid"}
Truth table33%1/3
A or B
A= $self->{"_user_rewrite_map"}B= $self->{"_group_rewrite_map"}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $file{"uid"}
Aresult
11
00
Truth table0%0/2
A
A= $file{"gid"}
Aresult
11
00
478 }
479 23 $file{src_path}= $real_src_path;
480 23 ▶ $file{data_path} //= $self->{src_abs} . $real_src_path;
Condition50%1/2
$file{"data_path"} //= $self->{"src_abs"} . $real_src_path
l!l
023
MC/DC0%0/1
$file{"data_path"} //= $self->{"src_abs"} . $real_src_path
$file{"data_path"}
Truth table50%1/2
A
A= $file{"data_path"}
Aresult
11
00
481 23 ▶ $file{name} //= $self->get_dst_for_src($real_src_path);
Condition33%1/3
$file{"name"} //= $self->get_dst_for_src($real_src_path)
l!l&&r!l&&!r
0230
MC/DC0%0/2
$file{"name"} //= $self->get_dst_for_src($real_src_path)
$file{"name"} $self->get_dst_for_src($real_src_path)
Truth table33%1/3
A //= B
A= $file{"name"}B= $self->get_dst_for_src($real_src_path)
ABresult
1X1
011
000
482 23 $self->{src_path_set}{$real_src_path}= $file{name};
483 23 ▶ $self->{src_path_set}{$src_path}= $file{name} if $real_src_path ne $src_path;
Branch: 1 branch
BranchTrueFalseTotal
if $real_src_path ne $src_path 2 21 23
484 }
485 $file{data_path}= $self->{src_abs} . $file{real_src_path}
486 if !defined $file{data} && !defined $file{data_path} && defined $file{real_src_path}
487 47 ▶ && -e $self->{src_abs} . $file{real_src_path};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $file{"data"} || defined $file{"data_path"} and defined $file{"real_src_path"} and -e $self->{"src_abs"} . $file{"real_src_path"} 0 47 47
Condition66%6/9
not defined $file{"data"} || defined $file{"data_path"} and defined $file{"real_src_path"} and -e $self->{"src_abs"} . $file{"real_src_path"}
!ll&&!rl&&r
4700
not defined $file{"data"} || defined $file{"data_path"} and defined $file{"real_src_path"}
!ll&&!rl&&r
4160
defined $file{'data'} || defined $file{'data_path'}
l!l&&r!l&&!r
10316
MC/DC0%0/4
not defined $file{"data"} || defined $file{"data_path"} and defined $file{"real_src_path"} and -e $self->{"src_abs"} . $file{"real_src_path"}
defined $file{'data'} defined $file{'data_path'} defined $file{"real_src_path"} -e $self->{"src_abs"} . $file{"real_src_path"}
Truth table60%3/5
not(A || B) and C and D
A= defined $file{'data'}B= defined $file{'data_path'}C= defined $file{"real_src_path"}D= -e $self->{"src_abs"} . $file{"real_src_path"}
ABCDresult
1XXX0
01XX0
000X0
00100
00111
488 47 ▶ $file{nlink} //= 1;
Condition100%2/2
$file{"nlink"} //= 1
l!l
3512
MC/DC100%1/1
$file{"nlink"} //= 1
$file{"nlink"}
Truth table100%2/2
A
A= $file{"nlink"}
Aresult
11
00
489  
490 47 ▶ if (defined $file{user} && !defined $file{uid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file{"user"} and not defined $file{"uid"}) 1 46 47
Condition66%2/3
defined $file{"user"} and not defined $file{"uid"}
!ll&&!rl&&r
4601
MC/DC50%1/2
defined $file{"user"} and not defined $file{"uid"}
defined $file{"user"} not defined $file{"uid"}
Truth table66%2/3
A and not(B)
A= defined $file{"user"}B= not defined $file{"uid"}
ABresult
0X0
100
111
491 1 ▶ $dst_userdb //= ($self->{dst_userdb} //= $self->_build_dst_userdb);
Condition33%2/6
$dst_userdb //= ($self->{"dst_userdb"} //= $self->_build_dst_userdb)
l!l&&r!l&&!r
010
$self->{"dst_userdb"} //= $self->_build_dst_userdb
l!l&&r!l&&!r
010
MC/DC0%0/2
$dst_userdb //= ($self->{"dst_userdb"} //= $self->_build_dst_userdb)
$dst_userdb ($self->{"dst_userdb"} //= $self->_build_dst_userdb)
MC/DC0%0/2
$self->{"dst_userdb"} //= $self->_build_dst_userdb
$self->{"dst_userdb"} $self->_build_dst_userdb
Truth table33%1/3
A //= B
A= $dst_userdbB= ($self->{"dst_userdb"} //= $self->_build_dst_userdb)
ABresult
1X1
011
000
Truth table33%1/3
A //= B
A= $self->{"dst_userdb"}B= $self->_build_dst_userdb
ABresult
1X1
011
000
492 my $u= $dst_userdb->user($file{user})
493 1 ▶ // croak "Unknown user '$file{user}' for file '$file{name}'";
Condition50%1/2
$dst_userdb->user($file{"user"}) // croak(qq[Unknown user '$file{"user"}' for file '$file{"name"}'])
l!l
10
MC/DC0%0/1
$dst_userdb->user($file{"user"}) // croak(qq[Unknown user '$file{"user"}' for file '$file{"name"}'])
$dst_userdb->user($file{"user"})
Truth table50%1/2
A
A= $dst_userdb->user($file{"user"})
Aresult
11
00
494 1 $file{uid}= $u->uid;
495 }
496 47 ▶ ++$self->{dst_uid_used}{$file{uid}} if defined $file{uid};
Branch: 1 branch
BranchTrueFalseTotal
if defined $file{"uid"} 39 8 47
497  
498 47 ▶ if (defined $file{group} && !defined $file{gid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file{"group"} and not defined $file{"gid"}) 1 46 47
Condition66%2/3
defined $file{"group"} and not defined $file{"gid"}
!ll&&!rl&&r
4601
MC/DC50%1/2
defined $file{"group"} and not defined $file{"gid"}
defined $file{"group"} not defined $file{"gid"}
Truth table66%2/3
A and not(B)
A= defined $file{"group"}B= not defined $file{"gid"}
ABresult
0X0
100
111
499 1 ▶ $dst_userdb //= ($self->{dst_userdb} //= $self->_build_dst_userdb);
Condition16%1/6
$dst_userdb //= ($self->{"dst_userdb"} //= $self->_build_dst_userdb)
l!l&&r!l&&!r
100
$self->{"dst_userdb"} //= $self->_build_dst_userdb
l!l&&r!l&&!r
000
MC/DC0%0/2
$dst_userdb //= ($self->{"dst_userdb"} //= $self->_build_dst_userdb)
$dst_userdb ($self->{"dst_userdb"} //= $self->_build_dst_userdb)
MC/DC0%0/2
$self->{"dst_userdb"} //= $self->_build_dst_userdb
$self->{"dst_userdb"} $self->_build_dst_userdb
Truth table33%1/3
A //= B
A= $dst_userdbB= ($self->{"dst_userdb"} //= $self->_build_dst_userdb)
ABresult
1X1
011
000
Truth table0%0/3
A //= B
A= $self->{"dst_userdb"}B= $self->_build_dst_userdb
ABresult
1X1
011
000
500 my $g= $dst_userdb->group($file{group})
501 1 ▶ // croak "Unknown group '$file{group}' for file '$file{name}'";
Condition50%1/2
$dst_userdb->group($file{"group"}) // croak(qq[Unknown group '$file{"group"}' for file '$file{"name"}'])
l!l
10
MC/DC0%0/1
$dst_userdb->group($file{"group"}) // croak(qq[Unknown group '$file{"group"}' for file '$file{"name"}'])
$dst_userdb->group($file{"group"})
Truth table50%1/2
A
A= $dst_userdb->group($file{"group"})
Aresult
11
00
502 1 $file{gid}= $g->gid;
503 }
504 47 ▶ ++$self->{dst_gid_used}{$file{gid}} if defined $file{gid};
Branch: 1 branch
BranchTrueFalseTotal
if defined $file{"gid"} 38 9 47
505  
506 # Has this destination already been written?
507 47 ▶ if (exists $self->{dst_path_set}{$file{name}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'dst_path_set'}{$file{'name'}}) { } 0 47 47
508 0 my $orig= $self->{dst_path_set}{$file{name}};
509 # If the destination is ::WriteFS, let it handle the collision below
510 0 ▶ unless ($self->_dst->can('dst_abs')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_dst->can("dst_abs")) 0 0 0
511 0 ▶ my $action= $self->on_collision // 'ignore_if_same';
Condition0%0/2
$self->on_collision // "ignore_if_same"
l!l
00
MC/DC0%0/1
$self->on_collision // "ignore_if_same"
$self->on_collision
Truth table0%0/2
A
A= $self->on_collision
Aresult
11
00
512 0 ▶ $action= $action->($file{name}, \%file)
Branch: 1 branch
BranchTrueFalseTotal
if ref $action eq "CODE" 0 0 0
513 if ref $action eq 'CODE';
514 0 ▶ if ($action eq 'ignore_if_same') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq "ignore_if_same") 0 0 0
515 0 ▶ $action= ($file{src_path}//'') eq $orig? 'ignore' : 'croak';
Branch: 1 branch
BranchTrueFalseTotal
($file{'src_path'} // '') eq $orig ? : 0 0 0
Condition0%0/2
$file{"src_path"} // ""
l!l
00
MC/DC0%0/1
$file{"src_path"} // ""
$file{"src_path"}
Truth table0%0/2
A
A= $file{"src_path"}
Aresult
11
00
516 }
517 0 ▶ if ($action eq 'ignore') {
Branch: 3 branches
BranchTrueFalseTotal
if ($action eq 'ignore') { } 0 0 0
elsif ($action eq 'overwrite') { } 0 0 0
elsif ($action eq 'croak') { } 0 0 0
518 0 $self->log->debugf("Already exported to '%s' previously from '%s'", $file{name}, $orig);
519 0 next;
520 } elsif ($action eq 'overwrite') {
521 0 $self->log->debugf("Overwriting '%s'", $file{name});
522 # let dst handle overwrite...
523 } elsif ($action eq 'croak') {
524 0 ▶ croak "Already exported '$file{name}'".(length $orig? " which came from $orig":"");
Branch: 1 branch
BranchTrueFalseTotal
length $orig ? : 0 0 0
525 } else {
526 0 croak "unhandled on_collision action '$action'";
527 }
528 }
529 }
530 # Else make sure the parent directory *has* been written
531 else {
532 47 my $dst_parent= $file{name} =~ s,/?[^/]+$,,r;
533 47 ▶ if (length $dst_parent && !exists $self->{dst_path_set}{$dst_parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $dst_parent and not exists $self->{"dst_path_set"}{$dst_parent}) 11 36 47
Condition100%3/3
length $dst_parent and not exists $self->{"dst_path_set"}{$dst_parent}
!ll&&!rl&&r
112511
MC/DC100%2/2
length $dst_parent and not exists $self->{"dst_path_set"}{$dst_parent}
length $dst_parent not exists $self->{"dst_path_set"}{$dst_parent}
Truth table100%3/3
A and not(B)
A= length $dst_parentB= not exists $self->{"dst_path_set"}{$dst_parent}
ABresult
0X0
100
111
534 11 $self->log->debugf(" parent dir '%s' is not exported yet", $dst_parent);
535 # if writing to a real dir, check whether it already exists by some other means
536 11 ▶ if ($self->_dst->can('dst_abs') && -d $self->_dst->dst_abs . $dst_parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_dst->can('dst_abs') and -d $self->_dst->dst_abs . $dst_parent) { } 0 11 11
Condition66%2/3
$self->_dst->can("dst_abs") and -d $self->_dst->dst_abs . $dst_parent
!ll&&!rl&&r
380
MC/DC0%0/2
$self->_dst->can("dst_abs") and -d $self->_dst->dst_abs . $dst_parent
$self->_dst->can("dst_abs") -d $self->_dst->dst_abs . $dst_parent
Truth table66%2/3
A and B
A= $self->_dst->can("dst_abs")B= -d $self->_dst->dst_abs . $dst_parent
ABresult
0X0
100
111
537 0 $self->log->debugf(" %s%s already exists in the filesystem", $self->_dst->dst_abs, $dst_parent);
538 # no need to do anything, but record that we have it
539 0 $self->{dst_path_set}{$dst_parent}= undef;
540 }
541 else {
542 # Determine which directory to copy permissions from
543 my $src_parent= !defined $file{src_path}? undef
544 11 ▶ : $file{src_path} =~ s,/?[^/]+$,,r;
Branch: 1 branch
BranchTrueFalseTotal
!defined($file{'src_path'}) ? : 3 8 11
545 # If no rewrites, src_parent is the same as dst_parent
546 11 ▶ if (!$self->_has_rewrites) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->_has_rewrites) { } 5 6 11
elsif (not length $src_parent or $self->get_dst_for_src($src_parent) ne $dst_parent) { } 4 2 6
547 5 ▶ $src_parent //= $dst_parent;
Condition33%1/3
$src_parent //= $dst_parent
l!l&&r!l&&!r
500
MC/DC0%0/2
$src_parent //= $dst_parent
$src_parent $dst_parent
Truth table33%1/3
A //= B
A= $src_parentB= $dst_parent
ABresult
1X1
011
000
548 5 $self->log->debugf(" will export %s first", $src_parent);
549 }
550 ▶ elsif (!length $src_parent || $self->get_dst_for_src($src_parent) ne $dst_parent) {
Condition100%3/3
not length $src_parent or $self->get_dst_for_src($src_parent) ne $dst_parent
l!l&&r!l&&!r
312
MC/DC100%2/2
not length $src_parent or $self->get_dst_for_src($src_parent) ne $dst_parent
not length $src_parent $self->get_dst_for_src($src_parent) ne $dst_parent
Truth table100%3/3
not(A) or B
A= not length $src_parentB= $self->get_dst_for_src($src_parent) ne $dst_parent
ABresult
1X1
011
000
551 # No src_path means we don't have an origin for this file, so no official
552 # origin for its parent directory, either. But, maybe a directory of the
553 # same name exists in src_path.
554 # If so, use it, else create a generic directory.
555 4 my %dir= ( name => $dst_parent );
556 4 ▶ if ((@dir{qw( dev ino mode nlink uid gid rdev size atime mtime ctime )}
Branch: 1 branch
BranchTrueFalseTotal
if (@dir{'dev', 'ino', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'size', 'atime', 'mtime', 'ctime'} = lstat $self->{'src_abs'} . $dst_parent and S_ISDIR($dir{'mode'})) { } 1 3 4
Condition66%2/3
@dir{"dev", "ino", "mode", "nlink", "uid", "gid", "rdev", "size", "atime", "mtime", "ctime"} = lstat $self->{"src_abs"} . $dst_parent and S_ISDIR($dir{"mode"})
!ll&&!rl&&r
301
MC/DC50%1/2
@dir{"dev", "ino", "mode", "nlink", "uid", "gid", "rdev", "size", "atime", "mtime", "ctime"} = lstat $self->{"src_abs"} . $dst_parent and S_ISDIR($dir{"mode"})
@dir{"dev", "ino", "mode", "nlink", "uid", "gid", "rdev", "size", "atime", "mtime", "ctime"} = lstat $self->{"src_abs"} . $dst_parent S_ISDIR($dir{"mode"})
Truth table66%2/3
A and B
A= @dir{"dev", "ino", "mode", "nlink", "uid", "gid", "rdev", "size", "atime", "mtime", "ctime"} = lstat $self->{"src_abs"} . $dst_parentB= S_ISDIR($dir{"mode"})
ABresult
0X0
100
111
557 = lstat $self->{src_abs} . $dst_parent)
558 && S_ISDIR($dir{mode})
559 ) {
560 1 $src_parent= \%dir;
561 1 $self->log->debugf(" will export %s first, using permissions from %s%s", $dst_parent, $self->{src_abs}, $dst_parent);
562 } else {
563 3 $src_parent= { name => $dst_parent, mode => (S_IFDIR | 0755) };
564 3 $self->log->debugf(" will export %s first, using default 0755 permissions", $dst_parent);
565 }
566 }
567 11 unshift @add, $src_parent, \%file;
568 11 next;
569 }
570 }
571 }
572 36 $self->{dst_path_set}{$file{name}}= $file{src_path};
573  
574 36 ▶ my $mode= $file{mode} // croak "attribute 'mode' is required, for $file{name}";
Condition50%1/2
$file{"mode"} // croak(qq[attribute 'mode' is required, for $file{"name"}])
l!l
360
MC/DC0%0/1
$file{"mode"} // croak(qq[attribute 'mode' is required, for $file{"name"}])
$file{"mode"}
Truth table50%1/2
A
A= $file{"mode"}
Aresult
11
00
575 36 ▶ if (S_ISREG($mode)) { $self->_export_file(\%file) }
Branch: 7 branches
BranchTrueFalseTotal
if (S_ISREG($mode)) { } 17 19 36
elsif (S_ISDIR($mode)) { } 12 7 19
elsif (S_ISLNK($mode)) { } 6 1 7
elsif (S_ISBLK($mode) or S_ISCHR($mode)) { } 0 1 1
elsif (S_ISFIFO($mode)) { } 0 1 1
elsif (S_ISSOCK($mode)) { } 1 0 1
elsif (S_ISWHT($mode)) { } 0 0 0
576 12 elsif (S_ISDIR($mode)) { $self->_export_dir(\%file) }
577 6 elsif (S_ISLNK($mode)) { $self->_export_symlink(\%file) }
578 0 ▶ elsif (S_ISBLK($mode) || S_ISCHR($mode)) { $self->_export_devnode(\%file) }
Condition33%1/3
S_ISBLK($mode) or S_ISCHR($mode)
l!l&&r!l&&!r
001
MC/DC0%0/2
S_ISBLK($mode) or S_ISCHR($mode)
S_ISBLK($mode) S_ISCHR($mode)
Truth table33%1/3
A or B
A= S_ISBLK($mode)B= S_ISCHR($mode)
ABresult
1X1
011
000
579 0 elsif (S_ISFIFO($mode)) { $self->_export_fifo(\%file) }
580 1 elsif (S_ISSOCK($mode)) { $self->_export_socket(\%file) }
581 0 elsif (S_ISWHT($mode)) { $self->_export_whiteout(\%file) }
582 else {
583 0 ▶ croak "Unhandled dir-ent type ".($mode & S_IFMT).' at "'.($file{src_path} // $file{data_path} // $file{name}).'"'
Condition0%0/6
($file{"src_path"} // $file{"data_path"}) // $file{"name"}
l!l&&r!l&&!r
000
$file{"src_path"} // $file{"data_path"}
l!l&&r!l&&!r
000
MC/DC0%0/3
($file{"src_path"} // $file{"data_path"}) // $file{"name"}
$file{"src_path"} $file{"data_path"} $file{"name"}
Truth table0%0/4
A // B // C
A= $file{"src_path"}B= $file{"data_path"}C= $file{"name"}
ABCresult
1XX1
01X1
0011
0000
584 }
585 }
586 22 $self;
587 }
588  
589  
590 9 ▶sub src_glob($self, @patterns) {
Subroutine src_glob: called CC=3 SCAR=11.0
Pod documented
591 9 my $src_abs= $self->src_abs;
592 # remove leading '/' from patterns
593 9 s{^/}{} for @patterns;
594 9 my @ret;
595 push @ret, map substr($_, length $src_abs), glob "$src_abs$_"
596 10 ▶ for @patterns;
Subroutine BEGIN: called CC=1 SCAR=0.0
597 9 return @ret;
598 }
599  
600  
601 9 ▶my sub isa_filter { ref $_[0] eq 'Regexp' || ref $_[0] eq 'CODE' }
Subroutine isa_filter: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "Regexp" or ref $_[0] eq "CODE" 2 7 9
602 5 ▶sub src_find($self, @paths) {
Subroutine src_find: called CC=11 SCAR=24.1
Pod documented
603 5 my $filter;
604 # The filter must be either the first or last argument
605 5 ▶ if (isa_filter $paths[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (isa_filter $paths[0]) { } 1 4 5
elsif (isa_filter $paths[-1]) { } 3 1 4
606 1 $filter= shift @paths;
607 } elsif (isa_filter $paths[-1]) {
608 3 $filter= pop @paths;
609 }
610 5 my ($src_abs, @ret, @todo, %seen)= ( $self->src_abs );
611 # If filter is a regexp-ref, upgrade it to a sub
612 5 ▶ if (ref $filter eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $filter eq "Regexp") 2 3 5
613 2 my $qr= $filter;
614 2 ▶ $filter= sub { $_ =~ $qr };
Subroutine __ANON__: called CC=1 SCAR=0.0
615 }
616 56 ▶ my $process= sub {
Subroutine __ANON__: called CC=10 SCAR=23.7
617 56 my %file= ( src_path => $_[0] );
618 56 local $_= $src_abs . $_[0];
619 56 ▶ return if $seen{$_}++; # within this call to src_find, don't return duplicates
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$_}++ 0 56 56
620 56 ▶ if (@file{qw( dev ino mode nlink uid gid rdev size atime mtime ctime )}= lstat) {
Branch: 1 branch
BranchTrueFalseTotal
if (@file{'dev', 'ino', 'mode', 'nlink', 'uid', 'gid', 'rdev', 'size', 'atime', 'mtime', 'ctime'} = lstat $_) { } 56 0 56
621 56 my $is_dir= -d;
622 56 ▶ push @ret, \%file if length $_[0] && (!defined $filter || $filter->(\%file));
Branch: 1 branch
BranchTrueFalseTotal
if length $_[0] and !defined($filter) || &$filter(\%file) 34 22 56
Condition100%6/6
length $_[0] and !defined($filter) || &$filter(\%file)
!ll&&!rl&&r
31934
not defined $filter or &$filter(\%file)
l!l&&r!l&&!r
52919
MC/DC100%3/3
length $_[0] and !defined($filter) || &$filter(\%file)
length $_[0] not defined $filter &$filter(\%file)
Truth table100%4/4
A and not(B) or C
A= length $_[0]B= not defined $filterC= &$filter(\%file)
ABCresult
0XX0
1000
11X1
1011
623 56 ▶ if ($is_dir && !delete $file{prune}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_dir and not delete $file{"prune"}) 13 43 56
Condition66%2/3
$is_dir and not delete $file{"prune"}
!ll&&!rl&&r
43013
MC/DC50%1/2
$is_dir and not delete $file{"prune"}
$is_dir not delete $file{"prune"}
Truth table66%2/3
A and not(B)
A= $is_dirB= not delete $file{"prune"}
ABresult
0X0
100
111
624 13 ▶ if (opendir my $dh, $src_abs . $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir my $dh, $src_abs . $_[0]) { } 13 0 13
625 13 ▶ push @todo, [ length $_[0]? $_[0].'/' : '', $dh ];
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] ? : 10 3 13
626 } else {
627 0 carp "Can't open $_: $!";
628 }
629 }
630 } else {
631 0 carp "Can't stat $_: $!";
632 }
633 5 };
634 5 ▶ push @paths, '' unless @paths;
Branch: 1 branch
BranchTrueFalseTotal
unless @paths 1 4 5
635 5 for my $path (@paths) {
636 5 ▶ $path //= '';
Condition50%1/2
$path //= ""
l!l
50
MC/DC0%0/1
$path //= ""
$path
Truth table50%1/2
A
A= $path
Aresult
11
00
637 5 $path =~ s,^/,,; # remove leading slash
638 5 $process->($path);
639 5 ▶ while (@todo) {
Branch: 1 branch
BranchTrueFalseTotal
if (@todo) 90 5 95
640 90 my $ent= readdir $todo[-1][1];
641 90 ▶ if (!defined $ent) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $ent) { } 13 77 90
elsif ($ent ne '.' and $ent ne '..') { } 51 39 90
642 13 closedir $todo[-1][1];
643 13 pop @todo;
644 }
645 ▶ elsif ($ent ne '.' && $ent ne '..') {
Condition100%3/3
$ent ne "." and $ent ne ".."
!ll&&!rl&&r
131351
MC/DC100%2/2
$ent ne "." and $ent ne ".."
$ent ne "." $ent ne ".."
Truth table100%3/3
A and B
A= $ent ne "."B= $ent ne ".."
ABresult
0X0
100
111
646 51 $process->($todo[-1][0] . $ent);
647 }
648 }
649 }
650 5 return @ret;
651 }
652  
653  
654 2 ▶sub src_which($self, $name) {
Subroutine src_which: called CC=6 SCAR=20.3
Pod documented
655 2 ▶ $name =~ m,/, and croak '->src_which($name) should not include a path separator';
Branch: 1 branch
BranchTrueFalseTotal
$name =~ m[/]u and croak("->src_which(\$name) should not include a path separator") 0 2 2
656 2 for ($self->src_exe_path_list) {
657 7 ▶ return "$_/$name" if -x $self->src_abs . "$_/$name"
Branch: 1 branch
BranchTrueFalseTotal
if -x $self->src_abs . "$_/$name" or $^O eq "MSWin32" and -e _ 2 5 7
Condition50%3/6
-x $self->src_abs . "$_/$name" or $^O eq "MSWin32" and -e _
l!l&&r!l&&!r
205
$^O eq "MSWin32" and -e _
!ll&&!rl&&r
500
MC/DC33%1/3
-x $self->src_abs . "$_/$name" or $^O eq "MSWin32" and -e _
-x $self->src_abs . "$_/$name" $^O eq "MSWin32" -e _
Truth table50%2/4
A or B and C
A= -x $self->src_abs . "$_/$name"B= $^O eq "MSWin32"C= -e _
ABCresult
1XX1
0111
00X0
0100
658 # -x isn't meaningful on Win32, so fall back to -e
659 or $^O eq 'MSWin32' && -e _;
660 }
661 0 return undef;
662 }
663  
664  
665 1 ▶sub skip($self, @paths) {
Subroutine skip: called CC=6 SCAR=19.5
Pod documented
666 1 for my $path (@paths) {
667 $path= $path->{src_path} // $path->{name}
668 23 ▶ // croak "Hashrefs passed to ->skip must include 'src_path' or 'name'"
Branch: 1 branch
BranchTrueFalseTotal
if &isa_hash($path) 23 0 23
Condition40%2/5
($path->{"src_path"} // $path->{"name"}) // croak("Hashrefs passed to ->skip must include 'src_path' or 'name'")
l!l
230
$path->{"src_path"} // $path->{"name"}
l!l&&r!l&&!r
2300
MC/DC0%0/2
($path->{"src_path"} // $path->{"name"}) // croak("Hashrefs passed to ->skip must include 'src_path' or 'name'")
$path->{"src_path"} $path->{"name"}
Truth table33%1/3
A // B
A= $path->{"src_path"}B= $path->{"name"}
ABresult
1X1
011
000
669 if isa_hash $path;
670 23 ▶ $self->{src_path_set}{$path =~ s,^/,,r} //= undef;
Condition100%2/2
$self->{"src_path_set"}{$path =~ s[^/][]ru} //= undef
l!l
122
MC/DC100%1/1
$self->{"src_path_set"}{$path =~ s[^/][]ru} //= undef
$self->{"src_path_set"}{$path =~ s[^/][]ru}
Truth table100%2/2
A
A= $self->{"src_path_set"}{$path =~ s[^/][]ru}
Aresult
11
00
671 }
672 1 $self;
673 }
674  
675  
676 2 ▶sub finish($self) {
Subroutine finish: called CC=1 SCAR=0.0
Pod documented
677 2 $self->_dst->finish;
678 2 undef $self->{tmp}; # allow File::Temp to free tmp dir
679 2 $self;
680 }
681  
682  
683 27 ▶sub get_dst_for_src($self, $path) {
Subroutine get_dst_for_src: called CC=2 SCAR=6.9
Pod documented
684 27 my $rre= $self->path_rewrite_regex;
685 27 my $rewrote= $path =~ s/^$rre/$self->{path_rewrite_map}{$1}/er;
686 27 ▶ $self->log->tracef(" rewrote '%s' to '%s'", $path, $rewrote)
Branch: 1 branch
BranchTrueFalseTotal
if $path ne $rewrote 8 19 27
687 if $path ne $rewrote;
688 27 return $rewrote;
689 }
690  
691  
692 0 ▶sub get_dst_uid_gid($self, $uid, $gid, $context='') {
Subroutine get_dst_uid_gid: not called CC=17 SCAR=57.2
Pod documented
693 # If dst_userdb is defined, convert these source uid/gid to names, then find the name
694 # in dst_userdb, then write those uid/gid. But, if _user_rewrite_map has an entry for
695 # the UID or user, then go with that.
696 0 my $dst_userdb= $self->{dst_userdb};
697 0 ▶ if ($dst_userdb || $self->{_user_rewrite_map} || $self->{_group_rewrite_map}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dst_userdb or $self->{"_user_rewrite_map"} or $self->{"_group_rewrite_map"}) 0 0 0
Condition0%0/6
$dst_userdb or $self->{"_user_rewrite_map"} or $self->{"_group_rewrite_map"}
l!l&&r!l&&!r
000
$dst_userdb or $self->{"_user_rewrite_map"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$dst_userdb or $self->{"_user_rewrite_map"} or $self->{"_group_rewrite_map"}
$dst_userdb $self->{"_user_rewrite_map"} $self->{"_group_rewrite_map"}
Truth table0%0/4
A or B or C
A= $dst_userdbB= $self->{"_user_rewrite_map"}C= $self->{"_group_rewrite_map"}
ABCresult
1XX1
01X1
0011
0000
698 0 my $dst_uid= $self->{_user_rewrite_map}{$uid};
699 0 my $dst_gid= $self->{_group_rewrite_map}{$gid};
700 0 ▶ if ($dst_userdb && !defined $dst_uid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dst_userdb and not defined $dst_uid) 0 0 0
Condition0%0/3
$dst_userdb and not defined $dst_uid
!ll&&!rl&&r
000
MC/DC0%0/2
$dst_userdb and not defined $dst_uid
$dst_userdb not defined $dst_uid
Truth table0%0/3
A and not(B)
A= $dst_userdbB= not defined $dst_uid
ABresult
0X0
100
111
701 0 ▶ my $src_userdb= ($self->{src_userdb} //= $self->_build_src_userdb);
Condition0%0/3
$self->{"src_userdb"} //= $self->_build_src_userdb
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"src_userdb"} //= $self->_build_src_userdb
$self->{"src_userdb"} $self->_build_src_userdb
Truth table0%0/3
A //= B
A= $self->{"src_userdb"}B= $self->_build_src_userdb
ABresult
1X1
011
000
702 0 ▶ my $src_user= $src_userdb->user($uid)
Branch: 1 branch
BranchTrueFalseTotal
my $src_user = $src_userdb->user($uid) or croak("Unknown UID $uid$context") 0 0 0
703 or croak "Unknown UID $uid$context";
704 0 $dst_uid= $self->{_user_rewrite_map}{$src_user->name};
705 0 ▶ if (!defined $dst_uid) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dst_uid) 0 0 0
706 0 ▶ my $dst_user= $dst_userdb->user($src_user->name)
Branch: 1 branch
BranchTrueFalseTotal
my $dst_user = $dst_userdb->user($src_user->name) or croak('User ' . $src_user->name . " not found in dst_userdb$context") 0 0 0
707 or croak "User ".$src_user->name." not found in dst_userdb$context";
708 0 $dst_uid= $dst_user->uid;
709 }
710 # cache it
711 0 $self->{_user_rewrite_map}{$src_user->name}= $dst_uid;
712 0 $self->{_user_rewrite_map}{$uid}= $dst_uid;
713 }
714 0 ▶ if ($dst_userdb && !defined $dst_gid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dst_userdb and not defined $dst_gid) 0 0 0
Condition0%0/3
$dst_userdb and not defined $dst_gid
!ll&&!rl&&r
000
MC/DC0%0/2
$dst_userdb and not defined $dst_gid
$dst_userdb not defined $dst_gid
Truth table0%0/3
A and not(B)
A= $dst_userdbB= not defined $dst_gid
ABresult
0X0
100
111
715 0 ▶ my $src_userdb= ($self->{src_userdb} //= $self->_build_src_userdb);
Condition0%0/3
$self->{"src_userdb"} //= $self->_build_src_userdb
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"src_userdb"} //= $self->_build_src_userdb
$self->{"src_userdb"} $self->_build_src_userdb
Truth table0%0/3
A //= B
A= $self->{"src_userdb"}B= $self->_build_src_userdb
ABresult
1X1
011
000
716 0 ▶ my $src_group= $src_userdb->group($gid)
Branch: 1 branch
BranchTrueFalseTotal
my $src_group = $src_userdb->group($gid) or croak("Unknown GID $gid$context") 0 0 0
717 or croak "Unknown GID $gid$context";
718 0 $dst_gid= $self->{_group_rewrite_map}{$src_group->name};
719 0 ▶ if (!defined $dst_gid) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dst_gid) 0 0 0
720 0 ▶ my $dst_group= $dst_userdb->group($src_group->name)
Branch: 1 branch
BranchTrueFalseTotal
my $dst_group = $dst_userdb->group($src_group->name) or croak('Group ' . $src_group->name . " not found in dst_userdb$context") 0 0 0
721 or croak "Group ".$src_group->name." not found in dst_userdb$context";
722 0 $dst_gid= $dst_group->gid;
723 }
724 # cache it
725 0 $self->{_group_rewrite_map}{$src_group->name}= $dst_gid;
726 0 $self->{_group_rewrite_map}{$gid}= $dst_gid;
727 }
728 0 return ($dst_uid, $dst_gid);
729 }
730 0 return ($uid, $gid);
731 }
732  
733 17 ▶sub _export_file($self, $file) {
Subroutine _export_file: called CC=11 SCAR=25.7
734 # If the file has a link count > 1, check to see if we already have it in the destination
735 17 my $prev;
736 17 ▶ if ($file->{nlink} > 1 && $file->{dev} && $file->{ino}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->{"nlink"} > 1 and $file->{"dev"} and $file->{"ino"}) 1 16 17
Condition66%4/6
$file->{"nlink"} > 1 and $file->{"dev"} and $file->{"ino"}
!ll&&!rl&&r
1601
$file->{"nlink"} > 1 and $file->{"dev"}
!ll&&!rl&&r
1601
MC/DC33%1/3
$file->{"nlink"} > 1 and $file->{"dev"} and $file->{"ino"}
$file->{"nlink"} > 1 $file->{"dev"} $file->{"ino"}
Truth table50%2/4
A and B and C
A= $file->{"nlink"} > 1B= $file->{"dev"}C= $file->{"ino"}
ABCresult
0XX0
10X0
1100
1111
737 1 ▶ if (defined($prev= $self->_link_map->{"$file->{dev}:$file->{ino}"})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($prev = $self->_link_map->{"$file->{'dev'}:$file->{'ino'}"})) { } 0 1 1
738 0 $self->log->debugf("Already exported inode %s:%s as '%s'", $file->{dev}, $file->{ino}, $prev);
739 # make a link of that file instead of copying again
740 0 $self->_log_action("LNK", $prev, $file->{name});
741 # ensure the dst realizes it is a hardlink by sending it without data
742 0 delete $file->{data};
743 0 delete $file->{data_path};
744 }
745 else {
746 1 $self->_link_map->{"$file->{dev}:$file->{ino}"}= $file->{name};
747 }
748 }
749 17 ▶ if (!defined $prev) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $prev) 17 0 17
750 # Normalize data to a scalar-ref
751 17 ▶ if (defined $file->{data_path}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $file->{'data_path'}) { } 9 8 17
elsif (not ref $file->{'data'}) { } 8 0 8
752 9 $file->{data}= Sys::Export::LazyFileData->new($file->{data_path});
753 } elsif (!ref $file->{data}) {
754 defined $file->{data}
755 8 ▶ or croak "For regular files, must specify ->{data} or ->{data_path}";
Branch: 1 branch
BranchTrueFalseTotal
defined $file->{"data"} or croak("For regular files, must specify ->{data} or ->{data_path}") 8 0 8
756 8 $file->{data}= \delete $file->{data};
757 }
758 17 my @notes;
759 $self->process_file($file, \@notes)
760 17 ▶ if length $file->{src_path};
Branch: 1 branch
BranchTrueFalseTotal
if length $file->{"src_path"} 9 8 17
761 17 ▶ $self->_log_action("CPY", $file->{src_path} // '(data)', $file->{name}, @notes);
Condition100%2/2
$file->{"src_path"} // "(data)"
l!l
98
MC/DC100%1/1
$file->{"src_path"} // "(data)"
$file->{"src_path"}
Truth table100%2/2
A
A= $file->{"src_path"}
Aresult
11
00
762 }
763 17 $self->_dst->add($file);
764 }
765  
766  
767 9 ▶sub process_file($self, $file, $notes) {
Subroutine process_file: called CC=3 SCAR=11.6
Pod documented
768 # Check for ELF signature or script-interpreter
769 9 ▶ if (substr(${$file->{data}}, 0, 4) eq "\x7fELF") {
Branch: 2 branches
BranchTrueFalseTotal
if (substr(${$file->{'data'};}, 0, 4) eq "\177ELF") { } 0 9 9
elsif (${$file->{'data'};} =~ m[^#!\s*/(\S+)]u) { } 1 8 9
770 0 $self->log->tracef("Detected ELF signature in '%s'", $file->{name});
771 0 $self->process_elf_file($file, $notes);
772 9 } elsif (${$file->{data}} =~ m,^#!\s*/(\S+),) {
773 1 $self->log->tracef("Detected script interpreter '%s' in '%s'", $1, $file->{name});
774 1 $self->process_script_file($file, $notes);
775 }
776 }
777  
778 0 ▶sub _resolve_src_library($self, $libname, $rpath) {
Subroutine _resolve_src_library: not called CC=5 SCAR=34.0
779 0 ▶ my @paths= ((grep length, split /:/, ($rpath//'')), $self->src_lib_path_list);
Condition0%0/2
$rpath // ""
l!l
00
MC/DC0%0/1
$rpath // ""
$rpath
Truth table0%0/2
A
A= $rpath
Aresult
11
00
780 0 for my $path (@paths) {
781 0 $path =~ s,^/,,; # remove leading slash because src_abs ends with slash
782 0 ▶ $path =~ s,(?<=[^/])\z,/, if length $path; # add trailing slash if it isn't the root
Branch: 1 branch
BranchTrueFalseTotal
if length $path 0 0 0
783 0 ▶ if (-e $self->{src_abs} . $path . $libname) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->{"src_abs"} . $path . $libname) 0 0 0
784 0 $self->log->tracef(" found %s at %s%s", $libname, $path, $libname);
785 0 return $path . $libname;
786 }
787 }
788 0 return ();
789 }
790  
791  
792 0 ▶sub process_elf_file($self, $file, $notes) {
Subroutine process_elf_file: not called CC=16 SCAR=56.1
Pod documented
793 0 require Sys::Export::ELF;
794 0 my $elf= Sys::Export::ELF::unpack(${$file->{data}});
795 0 my ($interpreter, @libs);
796 0 ▶ if ($elf->{dynamic}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elf->{"dynamic"}) 0 0 0
797 0 $self->log->debugf("Dynamic-linked ELF file: '%s' (src_path=%s)", $file->{name}, $file->{src_path});
798 0 ▶ if ($elf->{needed_libraries}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elf->{"needed_libraries"}) 0 0 0
799 0 for (@{$elf->{needed_libraries}}) {
800 0 ▶ my $lib= $self->_resolve_src_library($_, $elf->{rpath}) // carp("Can't find lib $_ needed for $file->{src_path}");
Condition0%0/3
$self->_resolve_src_library($_, $elf->{"rpath"}) // carp(qq[Can't find lib $_ needed for $file->{"src_path"}])
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->_resolve_src_library($_, $elf->{"rpath"}) // carp(qq[Can't find lib $_ needed for $file->{"src_path"}])
$self->_resolve_src_library($_, $elf->{"rpath"}) carp(qq[Can't find lib $_ needed for $file->{"src_path"}])
Truth table0%0/3
A // B
A= $self->_resolve_src_library($_, $elf->{"rpath"})B= carp(qq[Can't find lib $_ needed for $file->{"src_path"}])
ABresult
1X1
011
000
801 0 ▶ push @libs, $lib if $lib;
Branch: 1 branch
BranchTrueFalseTotal
if $lib 0 0 0
802 }
803 0 $self->add(@libs);
804 }
805 0 ▶ if (length $elf->{interpreter}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $elf->{"interpreter"}) 0 0 0
806 0 $elf->{interpreter} =~ s,^/,,;
807 0 $self->_elf_interpreters->{$elf->{interpreter}}= 1;
808 0 $interpreter= $elf->{interpreter};
809 0 $self->add($interpreter);
810 }
811 0 $self->log->debugf(" interpreter = %s, libs = %s", $interpreter, \@libs);
812 # Is any path rewriting requested?
813 0 ▶ if ($self->_has_rewrites && (defined $interpreter || @libs)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_rewrites and defined $interpreter || @libs) 0 0 0
Condition0%0/6
$self->_has_rewrites and defined $interpreter || @libs
!ll&&!rl&&r
000
defined $interpreter or @libs
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->_has_rewrites and defined $interpreter || @libs
$self->_has_rewrites defined $interpreter @libs
Truth table0%0/4
A and B or C
A= $self->_has_rewritesB= defined $interpreterC= @libs
ABCresult
0XX0
1000
11X1
1011
814 # If any dep gets its path rewritten, need to modify interpreter and/or rpath
815 0 my $rre= $self->path_rewrite_regex;
816 0 my @patchelf;
817 0 ▶ if (defined $interpreter && $interpreter =~ m/^$rre/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $interpreter and $interpreter =~ /^$rre/u) 0 0 0
Condition0%0/3
defined $interpreter and $interpreter =~ /^$rre/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $interpreter and $interpreter =~ /^$rre/u
defined $interpreter $interpreter =~ /^$rre/u
Truth table0%0/3
A and B
A= defined $interpreterB= $interpreter =~ /^$rre/u
ABresult
0X0
100
111
818 # the interpreter and rpath need to be absolute URLs, but within the logical root
819 # of 'dst'. They're already relative to 'dst', so just prefix a slash.
820 0 push @patchelf, '--set-interpreter' => '/'.$self->get_dst_for_src($interpreter);
821 }
822 0 ▶ if (grep m/^$rre/, @libs) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep /^$rre/u, @libs) 0 0 0
823 0 my %rpath;
824 0 for (@libs) {
825 0 my $dst_lib= $self->get_dst_for_src($_);
826 0 $dst_lib =~ s,[^/]+$,,; # path of lib
827 0 $rpath{$dst_lib}= 1;
828 }
829 0 ▶ if (keys %rpath) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %rpath) 0 0 0
830 0 push @patchelf, '--set-rpath' => join(':', map "/$_", keys %rpath);
831 }
832 }
833 0 ▶ if (@patchelf) {
Branch: 1 branch
BranchTrueFalseTotal
if (@patchelf) { } 0 0 0
834 0 $self->log->debug(join ' ', " patchelf rewrites: ", @patchelf);
835 # Create a temporary file so we can run patchelf on it
836 0 my $tmp= File::Temp->new(DIR => $self->tmp, UNLINK => 0);
837 0 _syswrite_all($tmp, $file->{data});
838 0 $tmp->close;
839 0 $self->_patchelf($tmp, @patchelf);
840 0 $file->{data}= map_or_load_file("$tmp");
841 0 push @$notes, '+patchelf';
842 } else {
843 0 $self->log->debug(" no interpreter/lib paths affected by rewrites");
844 }
845 }
846 }
847 }
848  
849  
850 1 ▶sub process_script_file($self, $file, $notes) {
Subroutine process_script_file: called CC=11 SCAR=34.1
Pod documented
851 # Make sure the interpreter is added, and also rewrite its path
852 1 ▶ my ($interp)= (${$file->{data}} =~ m,^#!\s*/(\S+),)
Branch: 1 branch
BranchTrueFalseTotal
my($interp) = ${$file->{"data"};} =~ m[^#!\s*/(\S+)]u or return 1 0 1
853 or return;
854 1 $self->add($interp);
855 1 ▶ if ($self->_has_rewrites) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_rewrites) 1 0 1
856 # rewrite the interpreter, if needed
857 1 my $rre= $self->path_rewrite_regex;
858 1 my $dst_interp= $interp;
859 1 ▶ if ($dst_interp =~ s,^$rre,$self->{path_rewrite_map}{$1},e) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dst_interp =~ s/^$rre/$self->{"path_rewrite_map"}{$1};/eu) 1 0 1
860 # note file->{data} could be a read-only memory map
861 1 my $data= ${$file->{data}} =~ s,^(#!\s*)(\S+),$1/$dst_interp,r;
862 1 $file->{data}= \$data;
863 1 push @$notes, '+rewrite interpreter';
864 }
865 }
866 1 ▶ if ($interp =~ m,^(usr/)?bin/env\z,) { # /usr/bin/env, request for interpreter from $PATH...
Branch: 1 branch
BranchTrueFalseTotal
if ($interp =~ m[^(usr/)?bin/env\z]u) 0 1 1
867 0 ▶ my ($name)= (${$file->{data}} =~ m,^#!\s*/\S+\s*(\S+),)
Branch: 1 branch
BranchTrueFalseTotal
my($name) = ${$file->{"data"};} =~ m[^#!\s*/\S+\s*(\S+)]u or return 0 0 0
868 or return;
869 0 ▶ if (defined (my $path= $self->src_which($name))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $path = $self->src_which($name))) { } 0 0 0
870 0 $self->add($path);
871 0 $interp= $path;
872 0 $self->log->tracef("Detected secondary script interpreter '%s' in '%s'", $path, $file->{name});
873 } else {
874 0 $self->log->tracef("Detected secondary script interpreter '%s' in '%s' but can't locate it", $name, $file->{name});
875 }
876 }
877  
878 1 $file->{interpreter}= $interp;
879 1 ▶ if ($interp =~ m,/perl[0-9.]*\z,) {
Branch: 3 branches
BranchTrueFalseTotal
if ($interp =~ m[/perl[0-9.]*\z]u) { } 0 1 1
elsif ($interp =~ m[/(bash|ash|dash|sh)\z]u) { } 1 0 1
elsif ($self->_has_rewrites and ${$file->{'data'};} =~ $self->path_rewrite_regex) { } 0 0 0
880 0 $self->process_perl_file($file, $notes);
881 }
882 elsif ($interp =~ m,/(bash|ash|dash|sh)\z,) {
883 1 $self->process_shell_file($file, $notes);
884 }
885 0 ▶ elsif ($self->_has_rewrites && ${$file->{data}} =~ $self->path_rewrite_regex) {
Condition0%0/3
$self->_has_rewrites and ${$file->{"data"};} =~ $self->path_rewrite_regex
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_has_rewrites and ${$file->{"data"};} =~ $self->path_rewrite_regex
$self->_has_rewrites ${$file->{"data"};} =~ $self->path_rewrite_regex
Truth table0%0/3
A and B
A= $self->_has_rewritesB= ${$file->{"data"};} =~ $self->path_rewrite_regex
ABresult
0X0
100
111
886 0 warn "$file->{src_path} is a script referencing a rewritten path, but don't know how to process it\n";
887 0 push @$notes, "+can't rewrite!";
888 }
889 }
890  
891  
892 1 ▶sub process_shell_file($self, $file, $notes) {
Subroutine process_shell_file: called CC=3 SCAR=11.3
Pod documented
893 # This takes the bold step of attempting to rewrite paths seen in the script
894 1 ▶ if ($self->_has_rewrites) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_rewrites) 1 0 1
895 1 my $rre= $self->path_rewrite_regex;
896 # Scan the source for paths that need rewritten
897 1 ▶ if (${$file->{data}} =~ $rre) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$file->{"data"};} =~ /$rre/u) 1 0 1
898 1 my ($interp_line, $body)= split "\n", ${$file->{data}}, 2;
899 # only replace path matches when following certain characters which
900 # indicate the start of a path.
901 0 $body =~ s/(?<=[ '"><\n#])$rre/$self->{path_rewrite_map}{$1}/ge;
902 1 $file->{data}= \"$interp_line\n$body";
903 1 push @$notes, '+rewrite paths';
904 }
905 }
906 }
907  
908  
909 0 ▶sub _get_perl_script_deps($self, $file) {
Subroutine _get_perl_script_deps: not called CC=9 SCAR=45.0
910 0 ▶ my $interp= $file->{interpreter} // $self->src_which('perl');
Condition0%0/3
$file->{"interpreter"} // $self->src_which("perl")
l!l&&r!l&&!r
000
MC/DC0%0/2
$file->{"interpreter"} // $self->src_which("perl")
$file->{"interpreter"} $self->src_which("perl")
Truth table0%0/3
A // B
A= $file->{"interpreter"}B= $self->src_which("perl")
ABresult
1X1
011
000
911 0 $self->log->tracef("Checking perl script %s for dependencies", $file->{name});
912 # We can run the actual perl interpreter with '-c' on this file, so long as
913 # src_path is defined and an strace implementation is available.
914 0 ▶ if ($self->_can_trace_deps && length $file->{src_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_can_trace_deps and length $file->{"src_path"}) 0 0 0
Condition0%0/3
$self->_can_trace_deps and length $file->{"src_path"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_can_trace_deps and length $file->{"src_path"}
$self->_can_trace_deps length $file->{"src_path"}
Truth table0%0/3
A and B
A= $self->_can_trace_depsB= length $file->{"src_path"}
ABresult
0X0
100
111
915 # If file appears to be a module, ensure module's own path root is in perl's @INC
916 0 my @inc;
917 0 ▶ if ($file->{src_path} =~ /.pm\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->{"src_path"} =~ /.pm\z/u) 0 0 0
918 0 ▶ if (${$file->{data}} =~ /^(package|class) (\S+)/m) {
Branch: 1 branch
BranchTrueFalseTotal
if (${$file->{"data"};} =~ /^(package|class) (\S+)/mu) 0 0 0
919 0 my $path= ($1 =~ s,::,/,gr).'.pm';
920 0 ▶ if (substr($file->{src_path}//'', -length $path) eq $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($file->{"src_path"} // "", -length($path)) eq $path) 0 0 0
Condition0%0/2
$file->{"src_path"} // ""
l!l
00
MC/DC0%0/1
$file->{"src_path"} // ""
$file->{"src_path"}
Truth table0%0/2
A
A= $file->{"src_path"}
Aresult
11
00
921 0 push @inc, substr($file->{src_path}, 0, -length $path);
922 }
923 }
924 }
925 0 my @cmd= ($interp, '-c', (map "-I$_", @inc), $file->{src_path} );
926 0 $self->log->debugf("Tracing perl deps with %s", \@cmd);
927 0 my $deps= eval { $self->_trace_deps(@cmd) };
928 0 ▶ return sort keys %$deps if defined $deps;
Branch: 1 branch
BranchTrueFalseTotal
if defined $deps 0 0 0
929 0 $self->log->debugf("strace failed: %s", $@);
930 }
931
932 0 $self->log->trace("strace unavailable, falling back to source scan");
933 0 return;
934 }
935  
936 0 ▶sub process_perl_file($self, $file, $notes) {
Subroutine process_perl_file: not called CC=3 SCAR=24.8
Pod documented
937 0 $self->add($self->_get_perl_script_deps($file));
938 0 ▶ if ($self->_has_rewrites && ${$file->{data}} =~ $self->path_rewrite_regex) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_rewrites and ${$file->{"data"};} =~ $self->path_rewrite_regex) 0 0 0
Condition0%0/3
$self->_has_rewrites and ${$file->{"data"};} =~ $self->path_rewrite_regex
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_has_rewrites and ${$file->{"data"};} =~ $self->path_rewrite_regex
$self->_has_rewrites ${$file->{"data"};} =~ $self->path_rewrite_regex
Truth table0%0/3
A and B
A= $self->_has_rewritesB= ${$file->{"data"};} =~ $self->path_rewrite_regex
ABresult
0X0
100
111
939 0 warn "$file->{src_path} is a script referencing a rewritten path, but don't know how to process it\n";
940 0 push @$notes, "+can't rewrite!";
941 }
942 }
943  
944 12 ▶sub _export_dir($self, $dir) {
Subroutine _export_dir: called CC=2 SCAR=6.9
945 12 ▶ $self->_log_action('DIR', $dir->{src_path} // '(default)', $dir->{name});
Condition100%2/2
$dir->{"src_path"} // "(default)"
l!l
75
MC/DC100%1/1
$dir->{"src_path"} // "(default)"
$dir->{"src_path"}
Truth table100%2/2
A
A= $dir->{"src_path"}
Aresult
11
00
946 12 $self->_dst->add($dir);
947 }
948  
949 6 ▶sub _export_symlink($self, $file) {
Subroutine _export_symlink: called CC=19 SCAR=31.8
950 6 ▶ if (!defined $file->{data}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file->{"data"}) 6 0 6
951 length $file->{data_path}
952 6 ▶ or croak "Symlink must contain 'data' or 'data_path'";
Branch: 1 branch
BranchTrueFalseTotal
length $file->{"data_path"} or croak("Symlink must contain 'data' or 'data_path'") 6 0 6
953 6 ▶ defined( my $target= readlink($file->{data_path}) )
Branch: 1 branch
BranchTrueFalseTotal
defined(my $target = readlink $file->{"data_path"}) or croak(qq[readlink($file->{"data_path"}): $!]) 6 0 6
954 or croak "readlink($file->{data_path}): $!";
955 6 $file->{data}= $target;
956 # Symlink referenced a source file, so also export the symlink target
957 # If target is relative and the data_path wasn't inside the src_abs tree, then not
958 # sensible to export it.
959 6 ▶ if ($target !~ m,^/, and substr($file->{data_path}, 0, length $self->{src_abs}) ne $self->{src_abs}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $target =~ m[^/]u and substr($file->{'data_path'}, 0, length $self->{'src_abs'}) ne $self->{'src_abs'}) { } 0 6 6
Condition66%2/3
not $target =~ m[^/]u and substr($file->{"data_path"}, 0, length $self->{"src_abs"}) ne $self->{"src_abs"}
!ll&&!rl&&r
330
MC/DC0%0/2
not $target =~ m[^/]u and substr($file->{"data_path"}, 0, length $self->{"src_abs"}) ne $self->{"src_abs"}
not $target =~ m[^/]u substr($file->{"data_path"}, 0, length $self->{"src_abs"}) ne $self->{"src_abs"}
Truth table66%2/3
not(A) and B
A= not $target =~ m[^/]uB= substr($file->{"data_path"}, 0, length $self->{"src_abs"}) ne $self->{"src_abs"}
ABresult
0X0
100
111
960 $self->log->debugf('Symlink %s read from %s which is outside %s; not adding symlink target %s',
961 0 $file->{name}, $file->{data_path}, $self->{src_abs}, $target);
962 }
963 else {
964 # make relative path absolute
965 6 ▶ $target= (substr($file->{data_path}, length $self->{src_abs}) =~ s,[^/]*\z,,r) . $target
Branch: 1 branch
BranchTrueFalseTotal
unless $target =~ m[^/]u 3 3 6
966 unless $target =~ m,^/,;
967 6 my $abs_target= $self->_src_parent_abs_path($target);
968 # Only queue it if it exists. Exporting dangling symlinks is not an error
969 6 ▶ if (defined $abs_target && lstat $self->{src_abs} . $abs_target) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $abs_target and lstat $self->{'src_abs'} . $abs_target) { } 5 1 6
Condition66%2/3
defined $abs_target and lstat $self->{"src_abs"} . $abs_target
!ll&&!rl&&r
015
MC/DC50%1/2
defined $abs_target and lstat $self->{"src_abs"} . $abs_target
defined $abs_target lstat $self->{"src_abs"} . $abs_target
Truth table66%2/3
A and B
A= defined $abs_targetB= lstat $self->{"src_abs"} . $abs_target
ABresult
0X0
100
111
970 5 $self->log->debugf("Queueing target '%s' of symlink '%s'", $target, $file->{name});
971 5 $self->add($target);
972 } else {
973 1 $self->log->debugf("Symlink '%s' target '%s' doesn't exist", $file->{name}, $target);
974 }
975 }
976 }
977  
978 6 ▶ if ($self->_has_rewrites && length $file->{src_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_rewrites and length $file->{"src_path"}) 1 5 6
Condition66%2/3
$self->_has_rewrites and length $file->{"src_path"}
!ll&&!rl&&r
501
MC/DC50%1/2
$self->_has_rewrites and length $file->{"src_path"}
$self->_has_rewrites length $file->{"src_path"}
Truth table66%2/3
A and B
A= $self->_has_rewritesB= length $file->{"src_path"}
ABresult
0X0
100
111
979 # Absolute links just need a simple rewrite on the target
980 1 ▶ if ($file->{data} =~ m,^/,) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->{'data'} =~ m[^/]u) { } 0 1 1
981 0 $file->{data}= $self->get_dst_for_src($file->{data});
982 }
983 # Relative links are tricky. A "100%" solution might actually be impossible, because
984 # users could intend for all sorts of different behavior with symlinks, but at least try
985 # to DWIM here.
986 else {
987 # Example: /usr/local/bin/foo -> ../../bin/bar, but both paths are being rewritten to /bin
988 # The correct symlink is then just /bin/foo -> bar
989 # Example: /usr/local/share/mydata -> ../../../opt/mydata, but /opt/mydata is a
990 # symlink to /opt/mydata-1.2.3, and /usr/local/share is getting rewritten to /share.
991 # The user may want this double redirection to remain so that mydata can be swapped
992 # for different versions, so can't just resolve everything to an absolute path.
993 # The correct symlink should probably be /share/mydata -> ../opt/mydata
994 # Example: /usr/local/share/mydata/lib -> ../../../../opt/mydata/current/../lib
995 # where /usr/local/share is getting rewritten and /opt/mydata is getting rewritten,
996 # and /opt/mydata/current is a symlink that breaks assumptions about '..'
997 # The correct symlink should probably be /share/mydata/lib -> ../../opt/mydata/current/../lib
998 # Note that /opt/mydata/current symlink might not even exist in dst yet (to be able
999 # to resolve it) and resolving the one in src might not be what the user wants.
1000
1001 # I think the answer here is to consume all leading '..' in the symlink path
1002 # (src_path is already absolute, so no danger of '..' meaning something different)
1003 # then add all following non-'..' to arrive at a new src_target, then rewrite that to
1004 # the corresponding dst_target, then create a relative path from the dst symlink to
1005 # that dst_path, then append any additional portions of the original symlink as-is.
1006 1 my @src_parts= split '/', $file->{src_path};
1007 1 pop @src_parts; # discard name of symlink itself
1008 1 my @target_parts= grep $_ ne '.', split '/', $file->{data};
1009 1 ▶ while (@target_parts && $target_parts[0] eq '..') {
Branch: 1 branch
BranchTrueFalseTotal
if (@target_parts and $target_parts[0] eq "..") 0 1 1
Condition33%1/3
@target_parts and $target_parts[0] eq ".."
!ll&&!rl&&r
010
MC/DC0%0/2
@target_parts and $target_parts[0] eq ".."
@target_parts $target_parts[0] eq ".."
Truth table33%1/3
A and B
A= @target_partsB= $target_parts[0] eq ".."
ABresult
0X0
100
111
1010 0 shift @target_parts;
1011 0 pop @src_parts;
1012 }
1013 1 ▶ while (@target_parts && $target_parts[0] ne '..') {
Branch: 1 branch
BranchTrueFalseTotal
if (@target_parts and $target_parts[0] ne "..") 1 1 2
Condition66%2/3
@target_parts and $target_parts[0] ne ".."
!ll&&!rl&&r
101
MC/DC50%1/2
@target_parts and $target_parts[0] ne ".."
@target_parts $target_parts[0] ne ".."
Truth table66%2/3
A and B
A= @target_partsB= $target_parts[0] ne ".."
ABresult
0X0
100
111
1014 1 push @src_parts, shift @target_parts;
1015 }
1016 1 my @dst_target= split '/', $self->get_dst_for_src(join '/', @src_parts);
1017 # now construct a relative path from $file->{name} to $dst_target
1018 1 my @dst_parts= split '/', $file->{name};
1019 1 pop @dst_parts; # discard name of symlink itself
1020 # remove common prefix
1021 1 ▶ while (@dst_parts && @dst_target && $dst_parts[0] eq $dst_target[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dst_parts and @dst_target and $dst_parts[0] eq $dst_target[0]) 3 1 4
Condition66%4/6
@dst_parts and @dst_target and $dst_parts[0] eq $dst_target[0]
!ll&&!rl&&r
103
@dst_parts and @dst_target
!ll&&!rl&&r
103
MC/DC33%1/3
@dst_parts and @dst_target and $dst_parts[0] eq $dst_target[0]
@dst_parts @dst_target $dst_parts[0] eq $dst_target[0]
Truth table50%2/4
A and B and C
A= @dst_partsB= @dst_targetC= $dst_parts[0] eq $dst_target[0]
ABCresult
0XX0
10X0
1100
1111
1022 3 shift @dst_parts;
1023 3 shift @dst_target;
1024 }
1025 # assemble '..' for each remaining piece of dst_parts, then the path to dst-target,
1026 # then the remainder of original path components (if any)
1027 1 $file->{data}= join '/', (('..') x scalar @dst_parts), @dst_target, @target_parts;
1028 }
1029 }
1030  
1031 6 $self->_log_action('SYM', '"'.$file->{data}.'"', $file->{name});
1032 6 $self->_dst->add($file);
1033 }
1034  
1035 0 ▶sub _export_devnode($self, $file) {
Subroutine _export_devnode: not called CC=7 SCAR=40.3
1036 0 ▶ if (defined $file->{rdev} && (!defined $file->{rdev_major} || !defined $file->{rdev_minor})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file->{"rdev"} and not defined $file->{"rdev_major"} && defined $file->{"rdev_minor"}) 0 0 0
Condition0%0/6
defined $file->{"rdev"} and not defined $file->{"rdev_major"} && defined $file->{"rdev_minor"}
!ll&&!rl&&r
000
defined $file->{'rdev_major'} && defined $file->{'rdev_minor'}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $file->{"rdev"} and not defined $file->{"rdev_major"} && defined $file->{"rdev_minor"}
defined $file->{"rdev"} defined $file->{'rdev_major'} defined $file->{'rdev_minor'}
Truth table0%0/4
A and not(B && C)
A= defined $file->{"rdev"}B= defined $file->{'rdev_major'}C= defined $file->{'rdev_minor'}
ABCresult
0XX0
1110
10X1
1101
1037 0 my ($major,$minor)= Sys::Export::Unix::_dev_major_minor($file->{rdev});
1038 0 ▶ $file->{rdev_major} //= $major;
Condition0%0/3
$file->{"rdev_major"} //= $major
l!l&&r!l&&!r
000
MC/DC0%0/2
$file->{"rdev_major"} //= $major
$file->{"rdev_major"} $major
Truth table0%0/3
A //= B
A= $file->{"rdev_major"}B= $major
ABresult
1X1
011
000
1039 0 ▶ $file->{rdev_minor} //= $minor;
Condition0%0/3
$file->{"rdev_minor"} //= $minor
l!l&&r!l&&!r
000
MC/DC0%0/2
$file->{"rdev_minor"} //= $minor
$file->{"rdev_minor"} $minor
Truth table0%0/3
A //= B
A= $file->{"rdev_minor"}B= $minor
ABresult
1X1
011
000
1040 }
1041 0 ▶ $self->_log_action(S_ISBLK($file->{mode})? 'BLK' : 'CHR', "$file->{rdev_major}:$file->{rdev_minor}", $file->{name});
Branch: 1 branch
BranchTrueFalseTotal
S_ISBLK($file->{'mode'}) ? : 0 0 0
1042 0 $self->_dst->add($file);
1043 }
1044  
1045 0 ▶sub _export_fifo($self, $file) {
Subroutine _export_fifo: not called CC=1 SCAR=6.9
1046 0 $self->_log_action("FIO", "(fifo)", $file->{name});
1047 0 $self->_dst->add($file);
1048 }
1049  
1050 1 ▶sub _export_socket($self, $file) {
Subroutine _export_socket: called CC=1 SCAR=0.0
1051 1 $self->_log_action("SOK", "(socket)", $file->{name});
1052 1 $self->_dst->add($file);
1053 }
1054  
1055 0 ▶sub _export_whiteout($self, $file) {
Subroutine _export_whiteout: not called CC=1 SCAR=6.9
1056 0 $self->_log_action("WHT", "(whiteout)", $file->{name});
1057 0 $self->_dst->add($file);
1058 }
1059  
1060 5 ▶sub _syswrite_all($tmp, $content_ref) {
Subroutine _syswrite_all: called CC=6 SCAR=29.1
1061 5 my $ofs= 0;
1062 5 again:
1063 my $wrote= $tmp->syswrite($$content_ref, length($$content_ref) - $ofs, $ofs);
1064 5 ▶ if ($ofs+$wrote != length $$content_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ofs + $wrote != length $$content_ref) 0 5 5
1065 0 ▶ if ($wrote > 0) { $ofs += $wrote; goto again; }
Branch: 2 branches
BranchTrueFalseTotal
if ($wrote > 0) { } 0 0 0
elsif ($!{'EAGAIN'} or $!{'EINTR'}) { } 0 0 0
1066 0 ▶ elsif ($!{EAGAIN} || $!{EINTR}) { goto again; }
Condition0%0/3
$!{"EAGAIN"} or $!{"EINTR"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$!{"EAGAIN"} or $!{"EINTR"}
$!{"EAGAIN"} $!{"EINTR"}
Truth table0%0/3
A or B
A= $!{"EAGAIN"}B= $!{"EINTR"}
ABresult
1X1
011
000
1067 0 else { die "syswrite($tmp): $!" }
1068 }
1069 5 ▶ $tmp->close or die "close($tmp): $!";
Branch: 1 branch
BranchTrueFalseTotal
$tmp->close or die "close($tmp): $!" 5 0 5
1070 }
1071  
1072 1 ▶sub _linux_major_minor($dev) {
Subroutine _linux_major_minor: called CC=1 SCAR=0.0
1073 10 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
1074 1 ( (($dev >> 8) & 0xfff) | (($dev >> 31 >> 1) & 0xfffff000) ),
1075 ( ($dev & 0xff) | (($dev >> 12) & 0xffffff00) )
1076 }
1077 1 ▶sub _system_mknod($path, $mode, $major, $minor) {
Subroutine _system_mknod: called CC=4 SCAR=15.8
1078 1 ▶ my @args= ("mknod", ($^O eq 'linux'? ("-m", sprintf("0%o", $mode & 0xFFF)) : ()),
Branch: 2 branches
BranchTrueFalseTotal
$^O eq 'linux' ? : 1 0 1
S_ISBLK($mode) ? : 0 1 1
1079 $path, S_ISBLK($mode)? "b":"c", $major, $minor);
1080 1 ▶ system(@args) == 0
Branch: 1 branch
BranchTrueFalseTotal
system(@args) == 0 or croak("mknod @args failed") 0 1 1
1081 or croak "mknod @args failed";
1082 }
1083  
1084 10 ▶if ($have_unix_mknod) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Sys::Export::Unix::have_unix_mknod) { } 0 10 10
1085 0 ▶ eval q{
Branch: 1 branch
BranchTrueFalseTotal
eval "\n sub _mknod_or_die(\$path, \$mode, \$major, \$minor) {\n Unix::Mknod::mknod(\$path, \$mode, Unix::Mknod::makedev(\$major, \$minor))\n or Carp::croak(\"mknod(\$path): \$!\");\n my \@stat= stat \$path\n or Carp::croak(\"mknod(\$path) failed silently\");\n # Sometimes mknod just creates a normal file when user lacks permission for device nodes\n (\$stat[2] & Fcntl::S_IFMT()) == (\$mode & Fcntl::S_IFMT()) or do { unlink \$path; Carp::croak(\"mknod failed to create mode \$mode at \$path\"); };\n 1;\n }\n sub _dev_major_minor(\$dev) { Unix::Mknod::major(\$dev), Unix::Mknod::minor(\$dev) }\n 1;\n " or die "$@" 0 0 0
1086 sub _mknod_or_die($path, $mode, $major, $minor) {
1087 Unix::Mknod::mknod($path, $mode, Unix::Mknod::makedev($major, $minor))
1088 or Carp::croak("mknod($path): $!");
1089 my @stat= stat $path
1090 or Carp::croak("mknod($path) failed silently");
1091 # Sometimes mknod just creates a normal file when user lacks permission for device nodes
1092 ($stat[2] & Fcntl::S_IFMT()) == ($mode & Fcntl::S_IFMT()) or do { unlink $path; Carp::croak("mknod failed to create mode $mode at $path"); };
1093 1;
1094 }
1095 sub _dev_major_minor($dev) { Unix::Mknod::major($dev), Unix::Mknod::minor($dev) }
1096 1;
1097 } or die "$@";
1098 } else {
1099 10 *_mknod_or_die= *_system_mknod;
1100 10 *_dev_major_minor= *_linux_major_minor;
1101 }
1102  
1103 0 ▶sub _capture_cmd {
Subroutine _capture_cmd: not called CC=2 SCAR=17.9
1104 0 require IPC::Open3;
1105 0 require Symbol;
1106 0 ▶ my $pid= IPC::Open3::open3(undef, my $out_fh, my $err_fh= Symbol::gensym(), @_)
Branch: 1 branch
BranchTrueFalseTotal
my $pid = IPC::Open3::open3(undef, my $out_fh, my $err_fh = &Symbol::gensym(), @_) or die "running @_ failed" 0 0 0
1107 or die "running @_ failed";
1108 0 waitpid($pid, 0);
1109 0 my $wstat= $?;
1110 0 local $/= undef;
1111 0 my $out= <$out_fh>;
1112 0 my $err= <$err_fh>;
1113 0 return ($out, $err, $wstat);
1114 }
1115  
1116 10 our $patchelf;
1117 0 ▶sub _patchelf($self, $path, @args) {
Subroutine _patchelf: not called CC=4 SCAR=30.0
1118 0 $self->log->tracef(" patchelf %s %s", \@args, $path);
1119 0 ▶ unless ($patchelf) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Sys::Export::Unix::patchelf) 0 0 0
1120 0 chomp($patchelf= `which patchelf`);
1121 0 ▶ croak "Missing tool 'patchelf'"
Branch: 1 branch
BranchTrueFalseTotal
unless $Sys::Export::Unix::patchelf 0 0 0
1122 unless $patchelf;
1123 }
1124 0 my ($out, $err, $wstat)= _capture_cmd($patchelf, @args, $path);
1125 0 ▶ $wstat == 0
Branch: 1 branch
BranchTrueFalseTotal
$wstat == 0 or croak("patchelf '${path}' failed: $err") 0 0 0
1126 or croak "patchelf '$path' failed: $err";
1127 0 1;
1128 }
1129  
1130 # Avoiding dependency on namespace::clean
1131 10 delete @{Sys::Export::Unix::}{qw(
1132 croak carp abs_path blessed looks_like_number max isa_hash isa_array isa_data_ref isa_handle
1133 isa_int isa_pow2 isa_export_dst isa_exporter isa_group isa_user isa_userdb S_IFMT
1134 map_or_load_file
1135 S_ISREG S_ISDIR S_ISLNK S_ISBLK S_ISCHR S_ISFIFO S_ISSOCK S_ISWHT
1136 S_IFREG S_IFDIR S_IFLNK S_IFBLK S_IFCHR S_IFIFO S_IFSOCK S_IFWHT
1137 )};
1138 10 1;
1139  
1140 __END__
« Export/Linux.pm ↑ Summary Export/CPIO.pm »