| Filename | /usr/local/perls/perl-5.26.1/lib/5.26.1/CPAN/Tarzip.pm |
| Statements | Executed 1365 statements in 64.4ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 62.1ms | 62.1ms | CPAN::Tarzip::CORE:system (opcode) |
| 3 | 3 | 2 | 2.15ms | 243ms | CPAN::Tarzip::gtest |
| 1 | 1 | 1 | 337µs | 121ms | CPAN::Tarzip::untar |
| 2 | 2 | 2 | 115µs | 169µs | CPAN::Tarzip::new |
| 13 | 7 | 1 | 84µs | 84µs | CPAN::Tarzip::CORE:match (opcode) |
| 1 | 1 | 1 | 67µs | 154ms | CPAN::Tarzip::TIEHANDLE |
| 2 | 1 | 1 | 58µs | 58µs | CPAN::Tarzip::CORE:ftsize (opcode) |
| 2 | 2 | 1 | 33µs | 145µs | CPAN::Tarzip::DESTROY |
| 4 | 2 | 1 | 23µs | 23µs | CPAN::Tarzip::_my_which |
| 0 | 0 | 0 | 0s | 0s | CPAN::Tarzip::BEGIN |
| 0 | 0 | 0 | 0s | 0s | CPAN::Tarzip::READ |
| 0 | 0 | 0 | 0s | 0s | CPAN::Tarzip::READLINE |
| 0 | 0 | 0 | 0s | 0s | CPAN::Tarzip::gunzip |
| 0 | 0 | 0 | 0s | 0s | CPAN::Tarzip::gzip |
| 0 | 0 | 0 | 0s | 0s | CPAN::Tarzip::unzip |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | # -*- Mode: cperl; coding: utf-8; cperl-indent-level: 4 -*- | ||||
| 2 | package CPAN::Tarzip; | ||||
| 3 | use strict; | ||||
| 4 | use vars qw($VERSION @ISA $BUGHUNTING); | ||||
| 5 | use CPAN::Debug; | ||||
| 6 | use File::Basename qw(basename); | ||||
| 7 | $VERSION = "5.5012"; | ||||
| 8 | # module is internal to CPAN.pm | ||||
| 9 | |||||
| 10 | @ISA = qw(CPAN::Debug); ## no critic | ||||
| 11 | $BUGHUNTING ||= 0; # released code must have turned off | ||||
| 12 | |||||
| 13 | # it's ok if file doesn't exist, it just matters if it is .gz or .bz2 | ||||
| 14 | # spent 169µs (115+54) within CPAN::Tarzip::new which was called 2 times, avg 84µs/call:
# once (78µs+35µs) by CPAN::Distribution::run_preps_on_packagedir at line 495 of CPAN/Distribution.pm
# once (37µs+19µs) by CPAN::Tarzip::TIEHANDLE at line 173 | ||||
| 15 | 2 | 2µs | my($class,$file) = @_; | ||
| 16 | 2 | 2µs | $CPAN::Frontend->mydie("CPAN::Tarzip->new called without arg") unless defined $file; | ||
| 17 | 2 | 7µs | my $me = { FILE => $file }; | ||
| 18 | 2 | 58µs | 2 | 23µs | if ($file =~ /\.(bz2|gz|zip|tbz|tgz)$/i) { # spent 23µs making 2 calls to CPAN::Tarzip::CORE:match, avg 12µs/call |
| 19 | $me->{ISCOMPRESSED} = 1; | ||||
| 20 | } else { | ||||
| 21 | $me->{ISCOMPRESSED} = 0; | ||||
| 22 | } | ||||
| 23 | 2 | 16µs | 2 | 8µs | if (0) { # spent 8µs making 2 calls to CPAN::Tarzip::CORE:match, avg 4µs/call |
| 24 | } elsif ($file =~ /\.(?:bz2|tbz)$/i) { | ||||
| 25 | unless ($me->{UNGZIPPRG} = $CPAN::Config->{bzip2}) { | ||||
| 26 | my $bzip2 = _my_which("bzip2"); | ||||
| 27 | if ($bzip2) { | ||||
| 28 | $me->{UNGZIPPRG} = $bzip2; | ||||
| 29 | } else { | ||||
| 30 | $CPAN::Frontend->mydie(qq{ | ||||
| 31 | CPAN.pm needs the external program bzip2 in order to handle '$file'. | ||||
| 32 | Please install it now and run 'o conf init bzip2' from the | ||||
| 33 | CPAN shell prompt to register it as external program. | ||||
| 34 | }); | ||||
| 35 | } | ||||
| 36 | } | ||||
| 37 | } else { | ||||
| 38 | 2 | 10µs | 2 | 15µs | $me->{UNGZIPPRG} = _my_which("gzip"); # spent 15µs making 2 calls to CPAN::Tarzip::_my_which, avg 8µs/call |
| 39 | } | ||||
| 40 | 2 | 5µs | 2 | 8µs | $me->{TARPRG} = _my_which("tar") || _my_which("gtar"); # spent 8µs making 2 calls to CPAN::Tarzip::_my_which, avg 4µs/call |
| 41 | 2 | 20µs | bless $me, $class; | ||
| 42 | } | ||||
| 43 | |||||
| 44 | sub _my_which { | ||||
| 45 | 4 | 2µs | my($what) = @_; | ||
| 46 | 4 | 45µs | if ($CPAN::Config->{$what}) { | ||
| 47 | return $CPAN::Config->{$what}; | ||||
| 48 | } | ||||
| 49 | if ($CPAN::META->has_inst("File::Which")) { | ||||
| 50 | return File::Which::which($what); | ||||
| 51 | } | ||||
| 52 | my @cand = MM->maybe_command($what); | ||||
| 53 | return $cand[0] if @cand; | ||||
| 54 | require File::Spec; | ||||
| 55 | my $component; | ||||
| 56 | PATH_COMPONENT: foreach $component (File::Spec->path()) { | ||||
| 57 | next unless defined($component) && $component; | ||||
| 58 | my($abs) = File::Spec->catfile($component,$what); | ||||
| 59 | if (MM->maybe_command($abs)) { | ||||
| 60 | return $abs; | ||||
| 61 | } | ||||
| 62 | } | ||||
| 63 | return; | ||||
| 64 | } | ||||
| 65 | |||||
| 66 | sub gzip { | ||||
| 67 | my($self,$read) = @_; | ||||
| 68 | my $write = $self->{FILE}; | ||||
| 69 | if ($CPAN::META->has_inst("Compress::Zlib")) { | ||||
| 70 | my($buffer,$fhw); | ||||
| 71 | $fhw = FileHandle->new($read) | ||||
| 72 | or $CPAN::Frontend->mydie("Could not open $read: $!"); | ||||
| 73 | my $cwd = `pwd`; | ||||
| 74 | my $gz = Compress::Zlib::gzopen($write, "wb") | ||||
| 75 | or $CPAN::Frontend->mydie("Cannot gzopen $write: $! (pwd is $cwd)\n"); | ||||
| 76 | binmode($fhw); | ||||
| 77 | $gz->gzwrite($buffer) | ||||
| 78 | while read($fhw,$buffer,4096) > 0 ; | ||||
| 79 | $gz->gzclose() ; | ||||
| 80 | $fhw->close; | ||||
| 81 | return 1; | ||||
| 82 | } else { | ||||
| 83 | my $command = CPAN::HandleConfig->safe_quote($self->{UNGZIPPRG}); | ||||
| 84 | system(qq{$command -c "$read" > "$write"})==0; | ||||
| 85 | } | ||||
| 86 | } | ||||
| 87 | |||||
| 88 | |||||
| 89 | sub gunzip { | ||||
| 90 | my($self,$write) = @_; | ||||
| 91 | my $read = $self->{FILE}; | ||||
| 92 | if ($CPAN::META->has_inst("Compress::Zlib")) { | ||||
| 93 | my($buffer,$fhw); | ||||
| 94 | $fhw = FileHandle->new(">$write") | ||||
| 95 | or $CPAN::Frontend->mydie("Could not open >$write: $!"); | ||||
| 96 | my $gz = Compress::Zlib::gzopen($read, "rb") | ||||
| 97 | or $CPAN::Frontend->mydie("Cannot gzopen $read: $!\n"); | ||||
| 98 | binmode($fhw); | ||||
| 99 | $fhw->print($buffer) | ||||
| 100 | while $gz->gzread($buffer) > 0 ; | ||||
| 101 | $CPAN::Frontend->mydie("Error reading from $read: $!\n") | ||||
| 102 | if $gz->gzerror != Compress::Zlib::Z_STREAM_END(); | ||||
| 103 | $gz->gzclose() ; | ||||
| 104 | $fhw->close; | ||||
| 105 | return 1; | ||||
| 106 | } else { | ||||
| 107 | my $command = CPAN::HandleConfig->safe_quote($self->{UNGZIPPRG}); | ||||
| 108 | system(qq{$command -d -c "$read" > "$write"})==0; | ||||
| 109 | } | ||||
| 110 | } | ||||
| 111 | |||||
| 112 | |||||
| 113 | # spent 243ms (2.15+241) within CPAN::Tarzip::gtest which was called 3 times, avg 81.1ms/call:
# once (1.11ms+151ms) by CPAN::Tarzip::TIEHANDLE at line 174
# once (1.03ms+90.3ms) by CPAN::Distribution::run_preps_on_packagedir at line 502 of CPAN/Distribution.pm
# once (6µs+0s) by CPAN::Tarzip::untar at line 323 | ||||
| 114 | 3 | 3µs | my($self) = @_; | ||
| 115 | 3 | 18µs | return $self->{GTEST} if exists $self->{GTEST}; | ||
| 116 | 2 | 1µs | defined $self->{FILE} or $CPAN::Frontend->mydie("gtest called but no FILE specified"); | ||
| 117 | 2 | 2µs | my $read = $self->{FILE}; | ||
| 118 | 2 | 2µs | my $success; | ||
| 119 | 2 | 52µs | 6 | 66.6ms | if ($read=~/\.(?:bz2|tbz)$/ && $CPAN::META->has_inst("Compress::Bzip2")) { # spent 66.5ms making 2 calls to CPAN::has_inst, avg 33.3ms/call
# spent 25µs making 4 calls to CPAN::Tarzip::CORE:match, avg 6µs/call |
| 120 | my($buffer,$len); | ||||
| 121 | $len = 0; | ||||
| 122 | my $gz = Compress::Bzip2::bzopen($read, "rb") | ||||
| 123 | or $CPAN::Frontend->mydie(sprintf("Cannot gzopen %s: %s\n", | ||||
| 124 | $read, | ||||
| 125 | $Compress::Bzip2::bzerrno)); | ||||
| 126 | while ($gz->bzread($buffer) > 0 ) { | ||||
| 127 | $len += length($buffer); | ||||
| 128 | $buffer = ""; | ||||
| 129 | } | ||||
| 130 | my $err = $gz->bzerror; | ||||
| 131 | $success = ! $err || $err == Compress::Bzip2::BZ_STREAM_END(); | ||||
| 132 | if ($len == -s $read) { | ||||
| 133 | $success = 0; | ||||
| 134 | CPAN->debug("hit an uncompressed file") if $CPAN::DEBUG; | ||||
| 135 | } | ||||
| 136 | $gz->gzclose(); | ||||
| 137 | CPAN->debug("err[$err]success[$success]") if $CPAN::DEBUG; | ||||
| 138 | } elsif ( $read=~/\.(?:gz|tgz)$/ && $CPAN::META->has_inst("Compress::Zlib") ) { | ||||
| 139 | # After I had reread the documentation in zlib.h, I discovered that | ||||
| 140 | # uncompressed files do not lead to an gzerror (anymore?). | ||||
| 141 | 2 | 2µs | my($buffer,$len); | ||
| 142 | 2 | 1µs | $len = 0; | ||
| 143 | 2 | 75µs | 2 | 12.3ms | my $gz = Compress::Zlib::gzopen($read, "rb") # spent 12.3ms making 2 calls to Compress::Zlib::gzopen, avg 6.17ms/call |
| 144 | or $CPAN::Frontend->mydie(sprintf("Cannot gzopen %s: %s\n", | ||||
| 145 | $read, | ||||
| 146 | $Compress::Zlib::gzerrno)); | ||||
| 147 | 2 | 7µs | 2 | 318µs | while ($gz->gzread($buffer) > 0 ) { # spent 318µs making 2 calls to Compress::Zlib::gzFile::gzread, avg 159µs/call |
| 148 | 632 | 176µs | $len += length($buffer); | ||
| 149 | 632 | 1.15ms | 632 | 162ms | $buffer = ""; # spent 162ms making 632 calls to Compress::Zlib::gzFile::gzread, avg 256µs/call |
| 150 | } | ||||
| 151 | 2 | 28µs | 2 | 7µs | my $err = $gz->gzerror; # spent 7µs making 2 calls to Compress::Zlib::gzFile::gzerror, avg 4µs/call |
| 152 | 2 | 6µs | 2 | 3µs | $success = ! $err || $err == Compress::Zlib::Z_STREAM_END(); # spent 3µs making 2 calls to Compress::Raw::Zlib::__ANON__[Compress/Raw/Zlib.pm:114], avg 2µs/call |
| 153 | 2 | 68µs | 2 | 58µs | if ($len == -s $read) { # spent 58µs making 2 calls to CPAN::Tarzip::CORE:ftsize, avg 29µs/call |
| 154 | $success = 0; | ||||
| 155 | CPAN->debug("hit an uncompressed file") if $CPAN::DEBUG; | ||||
| 156 | } | ||||
| 157 | 2 | 5µs | 2 | 233µs | $gz->gzclose(); # spent 233µs making 2 calls to Compress::Zlib::gzFile::gzclose, avg 116µs/call |
| 158 | 2 | 120µs | 4 | 57µs | CPAN->debug("err[$err]success[$success]") if $CPAN::DEBUG; # spent 41µs making 2 calls to IO::Uncompress::Base::DESTROY, avg 20µs/call
# spent 16µs making 2 calls to Compress::Raw::Zlib::inflateStream::DESTROY, avg 8µs/call |
| 159 | } elsif (!$self->{ISCOMPRESSED}) { | ||||
| 160 | $success = 0; | ||||
| 161 | } else { | ||||
| 162 | my $command = CPAN::HandleConfig->safe_quote($self->{UNGZIPPRG}); | ||||
| 163 | $success = 0==system(qq{$command -qdt "$read"}); | ||||
| 164 | } | ||||
| 165 | 2 | 24µs | return $self->{GTEST} = $success; | ||
| 166 | } | ||||
| 167 | |||||
| 168 | |||||
| 169 | # spent 154ms (67µs+154) within CPAN::Tarzip::TIEHANDLE which was called:
# once (67µs+154ms) by CPAN::Distribution::CHECKSUM_check_file at line 1527 of CPAN/Distribution.pm | ||||
| 170 | 1 | 1µs | my($class,$file) = @_; | ||
| 171 | 1 | 0s | my $ret; | ||
| 172 | 1 | 13µs | 1 | 86µs | $class->debug("file[$file]"); # spent 86µs making 1 call to CPAN::Debug::debug |
| 173 | 1 | 7µs | 1 | 56µs | my $self = $class->new($file); # spent 56µs making 1 call to CPAN::Tarzip::new |
| 174 | 1 | 31µs | 4 | 152ms | if (0) { # spent 152ms making 1 call to CPAN::Tarzip::gtest
# spent 28µs making 1 call to CPAN::has_inst
# spent 14µs making 2 calls to CPAN::Tarzip::CORE:match, avg 7µs/call |
| 175 | } elsif (!$self->gtest) { | ||||
| 176 | my $fh = FileHandle->new($file) | ||||
| 177 | or $CPAN::Frontend->mydie("Could not open file[$file]: $!"); | ||||
| 178 | binmode $fh; | ||||
| 179 | $self->{FH} = $fh; | ||||
| 180 | $class->debug("via uncompressed FH"); | ||||
| 181 | } elsif ($file =~ /\.(?:bz2|tbz)$/ && $CPAN::META->has_inst("Compress::Bzip2")) { | ||||
| 182 | my $gz = Compress::Bzip2::bzopen($file,"rb") or | ||||
| 183 | $CPAN::Frontend->mydie("Could not bzopen $file"); | ||||
| 184 | $self->{GZ} = $gz; | ||||
| 185 | $class->debug("via Compress::Bzip2"); | ||||
| 186 | } elsif ($file =~/\.(?:gz|tgz)$/ && $CPAN::META->has_inst("Compress::Zlib")) { | ||||
| 187 | 1 | 2µs | 1 | 1.88ms | my $gz = Compress::Zlib::gzopen($file,"rb") or # spent 1.88ms making 1 call to Compress::Zlib::gzopen |
| 188 | $CPAN::Frontend->mydie("Could not gzopen $file"); | ||||
| 189 | 1 | 2µs | $self->{GZ} = $gz; | ||
| 190 | 1 | 7µs | 1 | 81µs | $class->debug("via Compress::Zlib"); # spent 81µs making 1 call to CPAN::Debug::debug |
| 191 | } else { | ||||
| 192 | my $gzip = CPAN::HandleConfig->safe_quote($self->{UNGZIPPRG}); | ||||
| 193 | my $pipe = "$gzip -d -c $file |"; | ||||
| 194 | my $fh = FileHandle->new($pipe) or $CPAN::Frontend->mydie("Could not pipe[$pipe]: $!"); | ||||
| 195 | binmode $fh; | ||||
| 196 | $self->{FH} = $fh; | ||||
| 197 | $class->debug("via external $gzip"); | ||||
| 198 | } | ||||
| 199 | 1 | 5µs | $self; | ||
| 200 | } | ||||
| 201 | |||||
| 202 | |||||
| 203 | sub READLINE { | ||||
| 204 | my($self) = @_; | ||||
| 205 | if (exists $self->{GZ}) { | ||||
| 206 | my $gz = $self->{GZ}; | ||||
| 207 | my($line,$bytesread); | ||||
| 208 | $bytesread = $gz->gzreadline($line); | ||||
| 209 | return undef if $bytesread <= 0; | ||||
| 210 | return $line; | ||||
| 211 | } else { | ||||
| 212 | my $fh = $self->{FH}; | ||||
| 213 | return scalar <$fh>; | ||||
| 214 | } | ||||
| 215 | } | ||||
| 216 | |||||
| 217 | |||||
| 218 | sub READ { | ||||
| 219 | my($self,$ref,$length,$offset) = @_; | ||||
| 220 | $CPAN::Frontend->mydie("read with offset not implemented") if defined $offset; | ||||
| 221 | if (exists $self->{GZ}) { | ||||
| 222 | my $gz = $self->{GZ}; | ||||
| 223 | my $byteread = $gz->gzread($$ref,$length);# 30eaf79e8b446ef52464b5422da328a8 | ||||
| 224 | return $byteread; | ||||
| 225 | } else { | ||||
| 226 | my $fh = $self->{FH}; | ||||
| 227 | return read($fh,$$ref,$length); | ||||
| 228 | } | ||||
| 229 | } | ||||
| 230 | |||||
| 231 | |||||
| 232 | # spent 145µs (33+112) within CPAN::Tarzip::DESTROY which was called 2 times, avg 72µs/call:
# once (22µs+112µs) by CPAN::Distribution::CHECKSUM_check_file at line 1508 of CPAN/Distribution.pm
# once (11µs+0s) by CPAN::Distribution::run_preps_on_packagedir at line 596 of CPAN/Distribution.pm | ||||
| 233 | 2 | 1µs | my($self) = @_; | ||
| 234 | 2 | 5µs | if (exists $self->{GZ}) { | ||
| 235 | 1 | 1µs | my $gz = $self->{GZ}; | ||
| 236 | 1 | 4µs | 1 | 112µs | $gz->gzclose() if defined $gz; # hard to say if it is allowed # spent 112µs making 1 call to Compress::Zlib::gzFile::gzclose |
| 237 | # to be undef ever. AK, 2000-09 | ||||
| 238 | } else { | ||||
| 239 | 1 | 1µs | my $fh = $self->{FH}; | ||
| 240 | 1 | 1µs | $fh->close if defined $fh; | ||
| 241 | } | ||||
| 242 | 2 | 17µs | undef $self; | ||
| 243 | } | ||||
| 244 | |||||
| 245 | # spent 121ms (337µs+120) within CPAN::Tarzip::untar which was called:
# once (337µs+120ms) by CPAN::Distribution::untar_me at line 1203 of CPAN/Distribution.pm | ||||
| 246 | 1 | 1µs | my($self) = @_; | ||
| 247 | 1 | 1µs | my $file = $self->{FILE}; | ||
| 248 | 1 | 1µs | my($prefer) = 0; | ||
| 249 | |||||
| 250 | 1 | 0s | my $exttar = $self->{TARPRG} || ""; | ||
| 251 | 1 | 21µs | 1 | 10µs | $exttar = "" if $exttar =~ /^\s+$/; # user refuses to use it # spent 10µs making 1 call to CPAN::Tarzip::CORE:match |
| 252 | 1 | 9µs | my $extgzip = $self->{UNGZIPPRG} || ""; | ||
| 253 | 1 | 11µs | 1 | 1µs | $extgzip = "" if $extgzip =~ /^\s+$/; # user refuses to use it # spent 1µs making 1 call to CPAN::Tarzip::CORE:match |
| 254 | |||||
| 255 | 1 | 15µs | 2 | 58.3ms | if (0) { # makes changing order easier # spent 58.2ms making 1 call to CPAN::has_usable
# spent 35µs making 1 call to CPAN::has_inst |
| 256 | } elsif ($BUGHUNTING) { | ||||
| 257 | $prefer=2; | ||||
| 258 | } elsif ($CPAN::Config->{prefer_external_tar}) { | ||||
| 259 | $prefer = 1; | ||||
| 260 | } elsif ( | ||||
| 261 | $CPAN::META->has_usable("Archive::Tar") | ||||
| 262 | && | ||||
| 263 | $CPAN::META->has_inst("Compress::Zlib") ) { | ||||
| 264 | 1 | 27µs | my $prefer_external_tar = $CPAN::Config->{prefer_external_tar}; | ||
| 265 | 1 | 0s | unless (defined $prefer_external_tar) { | ||
| 266 | 1 | 13µs | 1 | 3µs | if ($^O =~ /(MSWin32|solaris)/) { # spent 3µs making 1 call to CPAN::Tarzip::CORE:match |
| 267 | $prefer_external_tar = 0; | ||||
| 268 | } else { | ||||
| 269 | 1 | 0s | $prefer_external_tar = 1; | ||
| 270 | } | ||||
| 271 | } | ||||
| 272 | 1 | 1µs | $prefer = $prefer_external_tar ? 1 : 2; | ||
| 273 | } elsif ($exttar && $extgzip) { | ||||
| 274 | # no modules and not bz2 | ||||
| 275 | $prefer = 1; | ||||
| 276 | # but solaris binary tar is a problem | ||||
| 277 | if ($^O eq 'solaris' && qx($exttar --version 2>/dev/null) !~ /gnu/i) { | ||||
| 278 | $CPAN::Frontend->mywarn(<< 'END_WARN'); | ||||
| 279 | |||||
| 280 | WARNING: Many CPAN distributions were archived with GNU tar and some of | ||||
| 281 | them may be incompatible with Solaris tar. We respectfully suggest you | ||||
| 282 | configure CPAN to use a GNU tar instead ("o conf init tar") or install | ||||
| 283 | a recent Archive::Tar instead; | ||||
| 284 | |||||
| 285 | END_WARN | ||||
| 286 | } | ||||
| 287 | } else { | ||||
| 288 | my $foundtar = $exttar ? "'$exttar'" : "nothing"; | ||||
| 289 | my $foundzip = $extgzip ? "'$extgzip'" : $foundtar ? "nothing" : "also nothing"; | ||||
| 290 | my $foundAT; | ||||
| 291 | if ($CPAN::META->has_usable("Archive::Tar")) { | ||||
| 292 | $foundAT = sprintf "'%s'", "Archive::Tar::"->VERSION; | ||||
| 293 | } else { | ||||
| 294 | $foundAT = "nothing"; | ||||
| 295 | } | ||||
| 296 | my $foundCZ; | ||||
| 297 | if ($CPAN::META->has_inst("Compress::Zlib")) { | ||||
| 298 | $foundCZ = sprintf "'%s'", "Compress::Zlib::"->VERSION; | ||||
| 299 | } elsif ($foundAT) { | ||||
| 300 | $foundCZ = "nothing"; | ||||
| 301 | } else { | ||||
| 302 | $foundCZ = "also nothing"; | ||||
| 303 | } | ||||
| 304 | $CPAN::Frontend->mydie(qq{ | ||||
| 305 | |||||
| 306 | CPAN.pm needs either the external programs tar and gzip -or- both | ||||
| 307 | modules Archive::Tar and Compress::Zlib installed. | ||||
| 308 | |||||
| 309 | For tar I found $foundtar, for gzip $foundzip. | ||||
| 310 | |||||
| 311 | For Archive::Tar I found $foundAT, for Compress::Zlib $foundCZ; | ||||
| 312 | |||||
| 313 | Can't continue cutting file '$file'. | ||||
| 314 | }); | ||||
| 315 | } | ||||
| 316 | 1 | 5µs | my $tar_verb = "v"; | ||
| 317 | 1 | 16µs | if (defined $CPAN::Config->{tar_verbosity}) { | ||
| 318 | $tar_verb = $CPAN::Config->{tar_verbosity} eq "none" ? "" : | ||||
| 319 | $CPAN::Config->{tar_verbosity}; | ||||
| 320 | } | ||||
| 321 | 1 | 0s | if ($prefer==1) { # 1 => external gzip+tar | ||
| 322 | 1 | 13µs | my($system); | ||
| 323 | 1 | 5µs | 1 | 6µs | my $is_compressed = $self->gtest(); # spent 6µs making 1 call to CPAN::Tarzip::gtest |
| 324 | 1 | 24µs | 1 | 44µs | my $tarcommand = CPAN::HandleConfig->safe_quote($exttar); # spent 44µs making 1 call to CPAN::HandleConfig::safe_quote |
| 325 | 1 | 11µs | if ($is_compressed) { | ||
| 326 | 1 | 4µs | 1 | 9µs | my $command = CPAN::HandleConfig->safe_quote($extgzip); # spent 9µs making 1 call to CPAN::HandleConfig::safe_quote |
| 327 | 1 | 5µs | $system = qq{$command -d -c }. | ||
| 328 | qq{< "$file" | $tarcommand x${tar_verb}f -}; | ||||
| 329 | } else { | ||||
| 330 | $system = qq{$tarcommand x${tar_verb}f "$file"}; | ||||
| 331 | } | ||||
| 332 | 1 | 62.2ms | 1 | 62.1ms | if (system($system) != 0) { # spent 62.1ms making 1 call to CPAN::Tarzip::CORE:system |
| 333 | # people find the most curious tar binaries that cannot handle | ||||
| 334 | # pipes | ||||
| 335 | if ($is_compressed) { | ||||
| 336 | (my $ungzf = $file) =~ s/\.gz(?!\n)\Z//; | ||||
| 337 | $ungzf = basename $ungzf; | ||||
| 338 | my $ct = CPAN::Tarzip->new($file); | ||||
| 339 | if ($ct->gunzip($ungzf)) { | ||||
| 340 | $CPAN::Frontend->myprint(qq{Uncompressed $file successfully\n}); | ||||
| 341 | } else { | ||||
| 342 | $CPAN::Frontend->mydie(qq{Couldn\'t uncompress $file\n}); | ||||
| 343 | } | ||||
| 344 | $file = $ungzf; | ||||
| 345 | } | ||||
| 346 | $system = qq{$tarcommand x${tar_verb}f "$file"}; | ||||
| 347 | $CPAN::Frontend->myprint(qq{Using Tar:$system:\n}); | ||||
| 348 | my $ret = system($system); | ||||
| 349 | if ($ret==0) { | ||||
| 350 | $CPAN::Frontend->myprint(qq{Untarred $file successfully\n}); | ||||
| 351 | } else { | ||||
| 352 | if ($? == -1) { | ||||
| 353 | $CPAN::Frontend->mydie(sprintf qq{Couldn\'t untar %s: '%s'\n}, | ||||
| 354 | $file, $!); | ||||
| 355 | } elsif ($? & 127) { | ||||
| 356 | $CPAN::Frontend->mydie(sprintf qq{Couldn\'t untar %s: child died with signal %d, %s coredump\n}, | ||||
| 357 | $file, ($? & 127), ($? & 128) ? 'with' : 'without'); | ||||
| 358 | } else { | ||||
| 359 | $CPAN::Frontend->mydie(sprintf qq{Couldn\'t untar %s: child exited with value %d\n}, | ||||
| 360 | $file, $? >> 8); | ||||
| 361 | } | ||||
| 362 | } | ||||
| 363 | return 1; | ||||
| 364 | } else { | ||||
| 365 | 1 | 61µs | return 1; | ||
| 366 | } | ||||
| 367 | } elsif ($prefer==2) { # 2 => modules | ||||
| 368 | unless ($CPAN::META->has_usable("Archive::Tar")) { | ||||
| 369 | $CPAN::Frontend->mydie("Archive::Tar not installed, please install it to continue"); | ||||
| 370 | } | ||||
| 371 | # Make sure AT does not use uid/gid/permissions in the archive | ||||
| 372 | # This leaves it to the user's umask instead | ||||
| 373 | local $Archive::Tar::CHMOD = 1; | ||||
| 374 | local $Archive::Tar::SAME_PERMISSIONS = 0; | ||||
| 375 | # Make sure AT leaves current user as owner | ||||
| 376 | local $Archive::Tar::CHOWN = 0; | ||||
| 377 | my $tar = Archive::Tar->new($file,1); | ||||
| 378 | my $af; # archive file | ||||
| 379 | my @af; | ||||
| 380 | if ($BUGHUNTING) { | ||||
| 381 | # RCS 1.337 had this code, it turned out unacceptable slow but | ||||
| 382 | # it revealed a bug in Archive::Tar. Code is only here to hunt | ||||
| 383 | # the bug again. It should never be enabled in published code. | ||||
| 384 | # GDGraph3d-0.53 was an interesting case according to Larry | ||||
| 385 | # Virden. | ||||
| 386 | warn(">>>Bughunting code enabled<<< " x 20); | ||||
| 387 | for $af ($tar->list_files) { | ||||
| 388 | if ($af =~ m!^(/|\.\./)!) { | ||||
| 389 | $CPAN::Frontend->mydie("ALERT: Archive contains ". | ||||
| 390 | "illegal member [$af]"); | ||||
| 391 | } | ||||
| 392 | $CPAN::Frontend->myprint("$af\n"); | ||||
| 393 | $tar->extract($af); # slow but effective for finding the bug | ||||
| 394 | return if $CPAN::Signal; | ||||
| 395 | } | ||||
| 396 | } else { | ||||
| 397 | for $af ($tar->list_files) { | ||||
| 398 | if ($af =~ m!^(/|\.\./)!) { | ||||
| 399 | $CPAN::Frontend->mydie("ALERT: Archive contains ". | ||||
| 400 | "illegal member [$af]"); | ||||
| 401 | } | ||||
| 402 | if ($tar_verb eq "v" || $tar_verb eq "vv") { | ||||
| 403 | $CPAN::Frontend->myprint("$af\n"); | ||||
| 404 | } | ||||
| 405 | push @af, $af; | ||||
| 406 | return if $CPAN::Signal; | ||||
| 407 | } | ||||
| 408 | $tar->extract(@af) or | ||||
| 409 | $CPAN::Frontend->mydie("Could not untar with Archive::Tar."); | ||||
| 410 | } | ||||
| 411 | |||||
| 412 | Mac::BuildTools::convert_files([$tar->list_files], 1) | ||||
| 413 | if ($^O eq 'MacOS'); | ||||
| 414 | |||||
| 415 | return 1; | ||||
| 416 | } | ||||
| 417 | } | ||||
| 418 | |||||
| 419 | sub unzip { | ||||
| 420 | my($self) = @_; | ||||
| 421 | my $file = $self->{FILE}; | ||||
| 422 | if ($CPAN::META->has_inst("Archive::Zip")) { | ||||
| 423 | # blueprint of the code from Archive::Zip::Tree::extractTree(); | ||||
| 424 | my $zip = Archive::Zip->new(); | ||||
| 425 | my $status; | ||||
| 426 | $status = $zip->read($file); | ||||
| 427 | $CPAN::Frontend->mydie("Read of file[$file] failed\n") | ||||
| 428 | if $status != Archive::Zip::AZ_OK(); | ||||
| 429 | $CPAN::META->debug("Successfully read file[$file]") if $CPAN::DEBUG; | ||||
| 430 | my @members = $zip->members(); | ||||
| 431 | for my $member ( @members ) { | ||||
| 432 | my $af = $member->fileName(); | ||||
| 433 | if ($af =~ m!^(/|\.\./)!) { | ||||
| 434 | $CPAN::Frontend->mydie("ALERT: Archive contains ". | ||||
| 435 | "illegal member [$af]"); | ||||
| 436 | } | ||||
| 437 | $status = $member->extractToFileNamed( $af ); | ||||
| 438 | $CPAN::META->debug("af[$af]status[$status]") if $CPAN::DEBUG; | ||||
| 439 | $CPAN::Frontend->mydie("Extracting of file[$af] from zipfile[$file] failed\n") if | ||||
| 440 | $status != Archive::Zip::AZ_OK(); | ||||
| 441 | return if $CPAN::Signal; | ||||
| 442 | } | ||||
| 443 | return 1; | ||||
| 444 | } elsif ( my $unzip = $CPAN::Config->{unzip} ) { | ||||
| 445 | my @system = ($unzip, $file); | ||||
| 446 | return system(@system) == 0; | ||||
| 447 | } | ||||
| 448 | else { | ||||
| 449 | $CPAN::Frontend->mydie(<<"END"); | ||||
| 450 | |||||
| 451 | Can't unzip '$file': | ||||
| 452 | |||||
| 453 | You have not configured an 'unzip' program and do not have Archive::Zip | ||||
| 454 | installed. Please either install Archive::Zip or else configure 'unzip' | ||||
| 455 | by running the command 'o conf init unzip' from the CPAN shell prompt. | ||||
| 456 | |||||
| 457 | END | ||||
| 458 | } | ||||
| 459 | } | ||||
| 460 | |||||
| 461 | 1; | ||||
| 462 | |||||
| 463 | __END__ | ||||
# spent 58µs within CPAN::Tarzip::CORE:ftsize which was called 2 times, avg 29µs/call:
# 2 times (58µs+0s) by CPAN::Tarzip::gtest at line 153, avg 29µs/call | |||||
# spent 84µs within CPAN::Tarzip::CORE:match which was called 13 times, avg 6µs/call:
# 4 times (25µs+0s) by CPAN::Tarzip::gtest at line 119, avg 6µs/call
# 2 times (23µs+0s) by CPAN::Tarzip::new at line 18, avg 12µs/call
# 2 times (14µs+0s) by CPAN::Tarzip::TIEHANDLE at line 174, avg 7µs/call
# 2 times (8µs+0s) by CPAN::Tarzip::new at line 23, avg 4µs/call
# once (10µs+0s) by CPAN::Tarzip::untar at line 251
# once (3µs+0s) by CPAN::Tarzip::untar at line 266
# once (1µs+0s) by CPAN::Tarzip::untar at line 253 | |||||
# spent 62.1ms within CPAN::Tarzip::CORE:system which was called:
# once (62.1ms+0s) by CPAN::Tarzip::untar at line 332 |