| 1 | # Copyright © 2008 Raphaël Hertzog <hertzog@debian.org> | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # GNU General Public License for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | Dpkg::Source::Archive - source tarball archive support | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | This module provides a class that implements support for handling | ||||||||||||||||||||||||||||||||||||||||||
| 25 | source tarballs. | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | B<Note>: This is a private module, its API can change at any time. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | package Dpkg::Source::Archive 0.01; | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | use v5.36; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use Errno qw(ENOENT); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | use Fcntl qw(:mode); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | use File::stat (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | ▶ | use File::Temp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | use File::Basename qw(basename); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | ▶ | use File::Find; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | use Dpkg (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | ▶ | use Dpkg::Gettext; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 2 | ▶ | use Dpkg::ErrorHandling; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | use Dpkg::IPC; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | use Dpkg::Source::Functions qw(erasedir fixperms); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | use parent qw(Dpkg::Compression::FileHandle); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my ($self, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $opts{options} //= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"options"} //= []
MC/DC0%0/1
$opts{"options"} //= []
$opts{"options"}
Truth table0%0/2
A
A= $opts{"options"}
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my %spawn_opts; | |||||||||||||||||||||||||||||||||||||||||
| 57 | # Possibly run tar from another directory. | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($opts{chdir}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $spawn_opts{chdir} = $opts{chdir}; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | *$self->{chdir} = $opts{chdir}; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # Redirect input/output appropriately. | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $self->ensure_open('w'); | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $spawn_opts{to_handle} = $self->get_filehandle(); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $spawn_opts{from_pipe} = \*$self->{tar_input}; | |||||||||||||||||||||||||||||||||||||||||
| 66 | # Try to use a deterministic mtime. | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $mtime = $opts{source_date} // $ENV{SOURCE_DATE_EPOCH} || time; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
($opts{'source_date'} // $ENV{'SOURCE_DATE_EPOCH'}) || time
$opts{"source_date"} // $ENV{"SOURCE_DATE_EPOCH"}
MC/DC0%0/2
($opts{'source_date'} // $ENV{'SOURCE_DATE_EPOCH'}) || time
$opts{"source_date"}
$ENV{"SOURCE_DATE_EPOCH"}
Truth table0%0/3
A // B
A= $opts{"source_date"}B= $ENV{"SOURCE_DATE_EPOCH"}
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | # Call tar creation process. | ||||||||||||||||||||||||||||||||||||||||||
| 69 | $spawn_opts{delete_env} = [ | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | 'TAR_OPTIONS', | |||||||||||||||||||||||||||||||||||||||||
| 71 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 72 | $spawn_opts{exec} = [ | ||||||||||||||||||||||||||||||||||||||||||
| 73 | $Dpkg::PROGTAR, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | '-cf', '-', | ||||||||||||||||||||||||||||||||||||||||||
| 75 | '--format=gnu', | ||||||||||||||||||||||||||||||||||||||||||
| 76 | '--sort=name', | ||||||||||||||||||||||||||||||||||||||||||
| 77 | '--mtime', "\@$mtime", | ||||||||||||||||||||||||||||||||||||||||||
| 78 | '--clamp-mtime', | ||||||||||||||||||||||||||||||||||||||||||
| 79 | '--null', | ||||||||||||||||||||||||||||||||||||||||||
| 80 | '--numeric-owner', '--owner=0', '--group=0', | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | @{$opts{options}}, | |||||||||||||||||||||||||||||||||||||||||
| 82 | '-T', '-', | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | *$self->{pid} = spawn(%spawn_opts); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | *$self->{cwd} = getcwd(); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub _add_entry { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_entry: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $cwd = *$self->{cwd}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | croak 'call create() first' unless *$self->{tar_input}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($file =~ m{^\Q$cwd\E/(.+)$}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | # Make pathname relative to the source root directory. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $file = $1; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | print({ *$self->{tar_input} } "$file\0") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | or syserr(g_('cannot write into tar input')); | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub add_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_file: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $testfile = $file; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if (*$self->{chdir}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $testfile = File::Spec->catfile(*$self->{chdir}, $file); | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | croak 'add_file() does not handle directories' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not -l $testfile and -d _
MC/DC0%0/2
not -l $testfile and -d _
not -l $testfile
-d _
Truth table0%0/3
not(A) and B
A= not -l $testfileB= -d _
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | if not -l $testfile and -d _; | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $self->_add_entry($file); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub add_directory { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_directory: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $testfile = $file; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if (*$self->{chdir}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $testfile = File::Spec->catdir(*$self->{chdir}, $file); | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | croak 'add_directory() only handles directories' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-l $testfile or not -d _
MC/DC0%0/2
-l $testfile or not -d _
-l $testfile
not -d _
Truth table0%0/3
A or not(B)
A= -l $testfileB= not -d _
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | if -l $testfile or not -d _; | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $self->_add_entry($file); | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub finish { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finish: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | close(*$self->{tar_input}) or syserr(g_('cannot close tar input')); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | wait_child(*$self->{pid}, cmdline => "$Dpkg::PROGTAR -cf -"); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | delete *$self->{pid}; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | delete *$self->{tar_input}; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | delete *$self->{cwd}; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | delete *$self->{chdir}; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $self->close(); | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | sub extract { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract: called CC=15 SCAR=34.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | my ($self, $dest, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | $opts{options} //= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"options"} //= []
MC/DC0%0/1
$opts{"options"} //= []
$opts{"options"}
Truth table50%1/2
A
A= $opts{"options"}
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | ▶ | $opts{in_place} //= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"in_place"} //= 0
MC/DC0%0/1
$opts{"in_place"} //= 0
$opts{"in_place"}
Truth table50%1/2
A
A= $opts{"in_place"}
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | $opts{no_fixperms} //= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"no_fixperms"} //= 0
MC/DC0%0/1
$opts{"no_fixperms"} //= 0
$opts{"no_fixperms"}
Truth table50%1/2
A
A= $opts{"no_fixperms"}
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | my %spawn_opts = ( | |||||||||||||||||||||||||||||||||||||||||
| 140 | wait_child => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # Prepare destination. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | unless (-e $dest) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | # Kludge so that realpath works. | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | mkdir($dest) or syserr(g_('cannot create directory %s'), $dest); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | my $tmpdir = File::Temp->newdir( | |||||||||||||||||||||||||||||||||||||||||
| 149 | TEMPLATE => basename($self->get_filename()) . '.tmp-extract.XXXXX', | ||||||||||||||||||||||||||||||||||||||||||
| 150 | DIR => Cwd::realpath("$dest/.."), | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | $spawn_opts{chdir} = $tmpdir; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | # Prepare stuff that handles the input of tar. | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | $self->ensure_open('r', | |||||||||||||||||||||||||||||||||||||||||
| 156 | delete_sig => [ | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 'PIPE', | ||||||||||||||||||||||||||||||||||||||||||
| 158 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 159 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | $spawn_opts{from_handle} = $self->get_filehandle(); | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | # Call tar extraction process. | ||||||||||||||||||||||||||||||||||||||||||
| 163 | $spawn_opts{delete_env} = [ | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | 'TAR_OPTIONS', | |||||||||||||||||||||||||||||||||||||||||
| 165 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 166 | $spawn_opts{exec} = [ | ||||||||||||||||||||||||||||||||||||||||||
| 167 | $Dpkg::PROGTAR, | ||||||||||||||||||||||||||||||||||||||||||
| 168 | '-xf', '-', | ||||||||||||||||||||||||||||||||||||||||||
| 169 | '--no-same-permissions', | ||||||||||||||||||||||||||||||||||||||||||
| 170 | '--no-same-owner', | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | @{$opts{options}}, | |||||||||||||||||||||||||||||||||||||||||
| 172 | ]; | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 2 | spawn(%spawn_opts); | |||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | $self->close(); | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | # Fix permissions on extracted files because tar insists on applying | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # our umask _to the original permissions_ rather than mostly-ignoring | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # the original permissions. | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # We still need --no-same-permissions because otherwise tar might | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # extract directory setgid (which we want inherited, not | ||||||||||||||||||||||||||||||||||||||||||
| 181 | # extracted); we need --no-same-owner because putting the owner | ||||||||||||||||||||||||||||||||||||||||||
| 182 | # back is tedious - in particular, correct group ownership would | ||||||||||||||||||||||||||||||||||||||||||
| 183 | # have to be calculated using mount options and other madness. | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | ▶ | fixperms($tmpdir) unless $opts{no_fixperms}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # If we are extracting "in-place" do not remove the destination directory. | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | if ($opts{in_place}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | my $canon_basedir = Cwd::realpath($dest); | |||||||||||||||||||||||||||||||||||||||||
| 189 | # On Solaris /dev/null points to /devices/pseudo/mm@0:null. | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | my $canon_devnull = Cwd::realpath('/dev/null'); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 6 | ▶ | my $check_symlink = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=20.5
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 6 | my $pathname = shift; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 6 | my $canon_pathname = Cwd::realpath($pathname); | |||||||||||||||||||||||||||||||||||||||||
| 194 | 6 | ▶ | if (not defined $canon_pathname) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | return if $! == ENOENT; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | syserr(g_("cannot canonicalize pathname '%s'"), $pathname); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | ▶ | return if $canon_pathname eq $canon_devnull; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 6 | ▶ | return if $canon_pathname eq $canon_basedir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | ▶ | return if $canon_pathname =~ m{^\Q$canon_basedir/\E}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | warning(g_("pathname '%s' points outside source root (to '%s')"), | |||||||||||||||||||||||||||||||||||||||||
| 203 | $pathname, $canon_pathname); | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 11 | ▶ | my $move_in_place = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=29.3
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 11 | my $relpath = File::Spec->abs2rel($File::Find::name, $tmpdir); | |||||||||||||||||||||||||||||||||||||||||
| 208 | 11 | my $destpath = File::Spec->catfile($dest, $relpath); | |||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 11 | ▶ | my $src_st = File::stat::lstat($File::Find::name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | or syserr(g_('cannot get source pathname %s metadata'), $File::Find::name); | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 11 | my $dst_st = File::stat::lstat($destpath); | |||||||||||||||||||||||||||||||||||||||||
| 213 | 11 | ▶ | if (! $dst_st && $! != ENOENT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $dst_st and $! != 2
MC/DC0%0/2
not $dst_st and $! != 2
not $dst_st
$! != 2
Truth table66%2/3
not(A) and B
A= not $dst_stB= $! != 2
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | syserr(g_('cannot get target pathname %s metadata'), $destpath); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 11 | ▶ | if (defined $dst_st) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 9 | ▶ | if (-d $dst_st && -d $src_st) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
-d $dst_st and -d $src_st
MC/DC50%1/2
-d $dst_st and -d $src_st
-d $dst_st
-d $src_st
Truth table66%2/3
A and B
A= -d $dst_stB= -d $src_st
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | # Refresh the destination directory attributes with the | ||||||||||||||||||||||||||||||||||||||||||
| 220 | # ones from the tarball. | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 3 | ▶ | chmod S_IMODE($src_st->mode), $destpath | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | or syserr(g_('cannot change directory %s mode'), $File::Find::name); | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 3 | ▶ | utime $src_st->atime, $src_st->mtime, $destpath | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | or syserr(g_('cannot change directory %s times'), $File::Find::name); | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | # We should do nothing, and just walk further tree. | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } elsif (-d $dst_st) { | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | rmdir $destpath | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | or syserr(g_('cannot remove destination directory %s'), $destpath); | ||||||||||||||||||||||||||||||||||||||||||
| 231 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 6 | $check_symlink->($destpath); | |||||||||||||||||||||||||||||||||||||||||
| 233 | 6 | ▶ | unlink $destpath | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | or syserr(g_('cannot remove destination file %s'), $destpath); | ||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | # If we are moving a directory, we do not need to walk it. | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 8 | ▶ | if (-d $src_st) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | 5 | $File::Find::prune = 1; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 8 | ▶ | rename $File::Find::name, $destpath | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | or syserr(g_('cannot move %s to %s'), $File::Find::name, $destpath); | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | my $scan_move_in_place = { | |||||||||||||||||||||||||||||||||||||||||
| 246 | wanted => $move_in_place, | ||||||||||||||||||||||||||||||||||||||||||
| 247 | no_chdir => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 248 | dangling_symlinks => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 249 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | find($scan_move_in_place, $tmpdir); | |||||||||||||||||||||||||||||||||||||||||
| 251 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | # Rename extracted directory. | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | opendir my $dir_dh, $tmpdir | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | or syserr(g_('cannot open directory %s'), $tmpdir); | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | my @entries = grep { $_ ne '.' && $_ ne '..' } readdir($dir_dh); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_ ne '.' && $_ ne '..'
MC/DC0%0/2
$_ ne '.' && $_ ne '..'
$_ ne '.'
$_ ne '..'
Truth table0%0/3
A && B
A= $_ ne '.'B= $_ ne '..'
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | closedir($dir_dh); | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | erasedir($dest); | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if (scalar(@entries) == 1 && ! -l "$tmpdir/$entries[0]" && -d _) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
scalar @entries == 1 and not -l "$tmpdir/$entries[0]" and -d _
scalar @entries == 1 and not -l "$tmpdir/$entries[0]"
MC/DC0%0/3
scalar @entries == 1 and not -l "$tmpdir/$entries[0]" and -d _
scalar @entries == 1
not -l "$tmpdir/$entries[0]"
-d _
Truth table0%0/4
A and not(B) and C
A= scalar @entries == 1B= not -l "$tmpdir/$entries[0]"C= -d _
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | rename "$tmpdir/$entries[0]", $dest | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | or syserr(g_('cannot rename %s to %s'), | ||||||||||||||||||||||||||||||||||||||||||
| 263 | "$tmpdir/$entries[0]", $dest); | ||||||||||||||||||||||||||||||||||||||||||
| 264 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | rename $tmpdir, $dest | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | or syserr(g_('cannot rename %s to %s'), $tmpdir, $dest); | ||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | erasedir($tmpdir); | |||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | =head1 CHANGES | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | =head2 Version 0.xx | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | This is a private module. | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||