| 1 | ##- Nanar <nanardon@mandriva.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, or (at your option) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ##- 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, write to the Free Software | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ##- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # $Id: Packdrakeng.pm 225631 2007-08-09 11:45:44Z nanardon $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | package MDV::Packdrakeng; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use POSIX qw(O_WRONLY O_TRUNC O_CREAT O_RDONLY O_APPEND); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use File::Path qw(mkpath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | our $VERSION = '1.13'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | my ($toc_header, $toc_footer) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ('cz[0', '0]cz'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # File::Temp qw(tempfile) hack to not require it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | ▶ | sub tempfile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tempfile: called CC=6 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | my ($count, $fname, $handle) = (0, undef, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 7 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | ▶ | ++$count > 10 and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | warn "Can't create temporary file ($fname)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return (undef, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | $fname = sprintf("%s/packdrakeng.%s.%s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | $ENV{TMPDIR} || '/tmp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | $$, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Generating an random name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 7 | ▶ | join("", map { $_=rand(51); $_ += $_ > 25 && $_ < 32 ? 91 : 65 ; chr($_) } (0 .. 4))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
$ENV{'TMPDIR'} || '/tmp'
$_ > 25 and $_ < 32
MC/DC0%0/1
$ENV{'TMPDIR'} || '/tmp'
$ENV{'TMPDIR'}
MC/DC100%2/2
$_ > 25 and $_ < 32
$_ > 25
$_ < 32
Truth table50%1/2
A
A= $ENV{'TMPDIR'}
Truth table100%3/3
A and B
A= $_ > 25B= $_ < 32
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } while !sysopen($handle, $fname, O_WRONLY | O_APPEND | O_CREAT); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 7 | return ($handle, $fname); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 10 | ▶ | sub method_info { "external $_[0]->{compress_method}/$_[0]->{uncompress_method} $VERSION" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
method_info: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 16 | ▶ | sub _new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new: called CC=7 SCAR=26.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 16 | my ($class, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | my $pack = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | filename => $options{archive}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | compress_method => $options{compress}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | uncompress_method => $options{uncompress}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | force_extern => $options{extern} || 0, # Don't use perl-zlib | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | noargs => $options{noargs}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # compression level, aka -X gzip or bzip option | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | level => defined($options{comp_level}) ? $options{comp_level} : 6, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # A compressed block will contain 400k of compressed data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | block_size => defined($options{block_size}) ? $options{block_size} : 400 * 1024, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | bufsize => $options{bufsize} || 65536, # Arbitrary buffer size to read files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # Internal data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | handle => undef, # Archive handle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # Toc information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | files => {}, # filename => { off, size, coff, csize } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | dir => {}, # dir => no matter what value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 'symlink' => {}, # file => link | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | coff => 0, # end of current compressed data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Data we need keep in memory to achieve the storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | current_block_files => {}, # Files in pending compressed block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | current_block_csize => 0, # Actual size in pending compressed block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | current_block_coff => 0, # The block block location (offset) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | current_block_off => 0, # Actual uncompressed file offset within the pending block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | cstream_data => undef, # Wrapper data we need to keep in memory (compression) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ustream_data => undef, # Wrapper data we need to keep in memory (uncompression) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # log and verbose function: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | log => $options{quiet} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | ? sub { our $error = "$_[0]\n" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | : sub { our $error = "$_[0]\n"; warn $error }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | debug => $options{debug} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | ? sub { my @w = @_; $w[0] = "Debug: $w[0]\n"; printf STDERR @w } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 76 | ▶ | : sub {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 16 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition75%3/4
$options{'extern'} || 0
$options{'bufsize'} || 65536
MC/DC100%1/1
$options{'extern'} || 0
$options{'extern'}
MC/DC0%0/1
$options{'bufsize'} || 65536
$options{'bufsize'}
Truth table100%2/2
A
A= $options{'extern'}
Truth table50%1/2
A
A= $options{'bufsize'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 16 | bless($pack, $class) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 8 | my ($class, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 8 | my $pack = _new($class, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 8 | ▶ | sysopen($pack->{handle}, $pack->{filename}, O_WRONLY | O_TRUNC | O_CREAT) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $pack->{log}("Can't open $pack->{filename}: $!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 8 | $pack->choose_compression_method(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 8 | $pack->{need_build_toc} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | $pack->{debug}( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 8 | "Creating new archive with %s.", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | $pack->method_info(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 8 | $pack | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 8 | ▶ | sub open { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 8 | my ($class, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | my $pack = _new($class, %options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 8 | ▶ | sysopen($pack->{handle}, $pack->{filename}, O_RDONLY) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | $pack->{log}("Can't open $pack->{filename}: $!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 8 | ▶ | $pack->read_toc() or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 8 | $pack->{debug}("Opening archive with %s.", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | $pack->method_info(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 8 | $pack | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # look $pack->{(un)compressed_method} and setup functions/commands to use | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # Have some facility about detecting we want gzip/bzip | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 16 | ▶ | sub choose_compression_method { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
choose_compression_method: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 16 | my ($pack) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | (!defined($pack->{compress_method}) && !defined($pack->{uncompress_method})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 16 | ▶ | and $pack->{compress_method} = "gzip"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $pack->{"compress_method"} or defined $pack->{"uncompress_method"}
MC/DC100%2/2
defined $pack->{"compress_method"} or defined $pack->{"uncompress_method"}
defined $pack->{"compress_method"}
defined $pack->{"uncompress_method"}
Truth table100%3/3
A or B
A= defined $pack->{"compress_method"}B= defined $pack->{"uncompress_method"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 16 | ▶ | my $test_method = $pack->{compress_method} || $pack->{uncompress_method}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$pack->{'compress_method'} || $pack->{'uncompress_method'}
MC/DC0%0/2
$pack->{'compress_method'} || $pack->{'uncompress_method'}
$pack->{'compress_method'}
$pack->{'uncompress_method'}
Truth table66%2/3
A || B
A= $pack->{'compress_method'}B= $pack->{'uncompress_method'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 16 | ▶ | $test_method =~ m/^bzip2|^bunzip2/ and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | $pack->{compress_method} ||= "bzip2"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$pack->{"compress_method"} ||= "bzip2"
MC/DC0%0/1
$pack->{"compress_method"} ||= "bzip2"
$pack->{"compress_method"}
Truth table50%1/2
A
A= $pack->{"compress_method"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 16 | ▶ | $test_method =~ m/^gzip|^gunzip/ and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 12 | ▶ | $pack->{compress_method} ||= "gzip"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pack->{"compress_method"} ||= "gzip"
MC/DC100%1/1
$pack->{"compress_method"} ||= "gzip"
$pack->{"compress_method"}
Truth table100%2/2
A
A= $pack->{"compress_method"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 12 | ▶ | if (!$pack->{force_extern}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 8 | require Compress::Zlib; #- need this to ensure that Packdrakeng::zlib will load properly | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 8 | require MDV::Packdrakeng::zlib; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 8 | bless($pack, 'MDV::Packdrakeng::zlib'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 16 | ▶ | if (!$pack->{noargs}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 12 | ▶ | $pack->{uncompress_method} ||= "$pack->{compress_method} -d"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$pack->{"uncompress_method"} ||= qq[$pack->{"compress_method"} -d]
MC/DC100%1/1
$pack->{"uncompress_method"} ||= qq[$pack->{"compress_method"} -d]
$pack->{"uncompress_method"}
Truth table100%2/2
A
A= $pack->{"uncompress_method"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 12 | ▶ | $pack->{compress_method} = $pack->{compress_method} ? "$pack->{compress_method} -$pack->{level}" : ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 16 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=5 SCAR=17.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 16 | my ($pack) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 16 | ▶ | $pack->{destroyed} and return; #- allow calling DESTROY | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 16 | $pack->{destroyed} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 16 | $pack->uncompress_handle(undef, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 16 | ▶ | $pack->build_toc() == 1 or die "Can't write toc into archive\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 16 | ▶ | close($pack->{handle}) if $pack->{handle}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 16 | ▶ | close($pack->{ustream_data}{handle}) if $pack->{ustream_data}{handle}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # Flush current compressed block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 16 | ▶ | sub build_toc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_toc: called CC=12 SCAR=28.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 16 | my ($pack) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 16 | ▶ | $pack->{need_build_toc} or return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 8 | $pack->end_block(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 8 | ▶ | $pack->end_seek() or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | $pack->{log}("Can't seek into archive"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 8 | my ($toc_length, $cf, $cd, $cl) = (0, 0, 0, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 8 | foreach my $entry (keys %{$pack->{'dir'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | $cd++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | ▶ | my $w = syswrite($pack->{handle}, $entry . "\n") or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $pack->{log}("Can't write toc into archive"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | $toc_length += $w; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 8 | foreach my $entry (keys %{$pack->{'symlink'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | $cl++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | ▶ | my $w = syswrite($pack->{handle}, sprintf("%s\n%s\n", $entry, $pack->{'symlink'}{$entry})) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $pack->{log}("Can't write toc into archive"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | $toc_length += $w | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 8 | foreach my $entry (sort keys %{$pack->{files}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 64 | $cf++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 64 | ▶ | my $w = syswrite($pack->{handle}, $entry ."\n") or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $pack->{log}("Can't write toc into archive"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 64 | $toc_length += $w; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 8 | foreach my $file (sort keys %{$pack->{files}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 64 | my $entry = $pack->{files}{$file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 64 | ▶ | syswrite($pack->{handle}, pack('NNNN', $entry->{coff}, $entry->{csize}, $entry->{off}, $entry->{size})) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $pack->{log}("Can't write toc into archive"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | syswrite($pack->{handle}, pack("a4NNNNa40a4", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | $toc_header, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | $cd, $cl, $cf, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | $toc_length, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | $pack->{uncompress_method}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 8 | ▶ | $toc_footer)) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $pack->{log}("Can't write toc into archive"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 8 | ▶ | sub read_toc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_toc: called CC=8 SCAR=21.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 8 | my ($pack) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 8 | sysseek($pack->{handle}, -64, 2) ; #or return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 8 | sysread($pack->{handle}, my $buf, 64);# == 64 or return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 8 | my ($header, $toc_d_count, $toc_l_count, $toc_f_count, $toc_str_size, $uncompress, $trailer) = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | unpack("a4NNNNZ40a4", $buf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 8 | ▶ | $header eq $toc_header && $trailer eq $toc_footer or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$header eq $toc_header and $trailer eq $toc_footer
MC/DC0%0/2
$header eq $toc_header and $trailer eq $toc_footer
$header eq $toc_header
$trailer eq $toc_footer
Truth table33%1/3
A and B
A= $header eq $toc_headerB= $trailer eq $toc_footer
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $pack->{log}("Error reading toc: wrong header/trailer"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 8 | ▶ | $pack->{uncompress_method} ||= $uncompress; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$pack->{"uncompress_method"} ||= $uncompress
MC/DC0%0/2
$pack->{"uncompress_method"} ||= $uncompress
$pack->{"uncompress_method"}
$uncompress
Truth table66%2/3
A ||= B
A= $pack->{"uncompress_method"}B= $uncompress
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 8 | $pack->choose_compression_method(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | sysseek($pack->{handle}, -64 - ($toc_str_size + 16 * $toc_f_count) ,2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 8 | sysread($pack->{handle}, my $fileslist, $toc_str_size); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 8 | my @filenames = split("\n", $fileslist); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 8 | sysread($pack->{handle}, my $sizes_offsets, 16 * $toc_f_count); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 8 | my @size_offset = unpack("N" . 4*$toc_f_count, $sizes_offsets); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 8 | foreach (1 .. $toc_d_count) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | $pack->{dir}{shift(@filenames)} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 8 | foreach (1 .. $toc_l_count) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | my $n = shift(@filenames); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | $pack->{'symlink'}{$n} = shift(@filenames); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 8 | foreach (1 .. $toc_f_count) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 64 | my $f = shift(@filenames); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 64 | $pack->{files}{$f}{coff} = shift(@size_offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 64 | $pack->{files}{$f}{csize} = shift(@size_offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 64 | $pack->{files}{$f}{off} = shift(@size_offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 64 | $pack->{files}{$f}{size} = shift(@size_offset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # looking for offset for this archive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | $pack->{files}{$f}{coff} + $pack->{files}{$f}{csize} > $pack->{coff} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 64 | ▶ | and $pack->{coff} = $pack->{files}{$f}{coff} + $pack->{files}{$f}{csize}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 8 | $pack->{toc_f_count} = $toc_f_count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 8 | ▶ | sub sort_files_by_packing { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort_files_by_packing: called CC=4 SCAR=14.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 8 | my ($pack, @files) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | sort { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 8 | defined($pack->{files}{$a}) && defined($pack->{files}{$b}) ? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | ($pack->{files}{$a}{coff} == $pack->{files}{$b}{coff} ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | $pack->{files}{$a}{off} <=> $pack->{files}{$b}{off} : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 124 | ▶ | $pack->{files}{$a}{coff} <=> $pack->{files}{$b}{coff}) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $pack->{"files"}{$a} and defined $pack->{"files"}{$b}
MC/DC0%0/2
defined $pack->{"files"}{$a} and defined $pack->{"files"}{$b}
defined $pack->{"files"}{$a}
defined $pack->{"files"}{$b}
Truth table33%1/3
A and B
A= defined $pack->{"files"}{$a}B= defined $pack->{"files"}{$b}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | $a cmp $b | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } @files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # Goto to the end of written compressed data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 91 | ▶ | sub end_seek { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end_seek: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 91 | my ($pack) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 91 | ▶ | my $seekvalue = $pack->direct_write ? $pack->{coff} + $pack->{current_block_csize} : $pack->{coff}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 91 | sysseek($pack->{handle}, $seekvalue, 0) == $seekvalue | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | #- To terminate a compressed block, flush the pending compressed data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | #- fill toc data still unknown | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 19 | ▶ | sub end_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
end_block: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 19 | my ($pack) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 19 | ▶ | $pack->end_seek() or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 19 | my (undef, $csize) = $pack->compress_handle(undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 19 | $pack->{current_block_csize} += $csize; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 19 | foreach (keys %{$pack->{current_block_files}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 64 | $pack->{files}{$_} = $pack->{current_block_files}{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 64 | $pack->{files}{$_}{csize} = $pack->{current_block_csize}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 19 | $pack->{coff} += $pack->{current_block_csize}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 19 | $pack->{current_block_coff} += $pack->{current_block_csize}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 19 | $pack->{current_block_csize} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 19 | $pack->{current_block_files} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 19 | $pack->{current_block_off} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | ####################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # Compression wrapper # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | ####################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # true if wrapper writes directly in archive and not into temp file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 53 | ▶ | sub direct_write { 0; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
direct_write: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 49 | ▶ | sub compress_handle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compress_handle: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 49 | my ($pack, $sourcefh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 49 | my ($insize, $outsize) = (0, 0); # aka uncompressed / compressed data length | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 49 | ▶ | if (!defined($sourcefh)) { # bloc flush call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 4 | return 0, $pack->compress_data(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 45 | ▶ | while (my $length = sysread($sourcefh, my $data, $pack->{bufsize})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 369 | $outsize += $pack->compress_data($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 369 | $insize += $length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 45 | return ($insize, $outsize) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 373 | ▶ | sub compress_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compress_data: called CC=10 SCAR=23.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 373 | my ($pack, $data) = ($_[0], \$_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 373 | my ($outsize) = (0); # aka uncompressed / compressed data length | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 373 | my $hout; # handle for gzip | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 373 | ▶ | if (defined($pack->{cstream_data})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 369 | $hout = $pack->{cstream_data}{hout}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 373 | ▶ | if (defined($$data)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 369 | ▶ | if (!defined($pack->{cstream_data})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 3 | my $hin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 3 | ($hin, $pack->{cstream_data}{file_block}) = tempfile(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 3 | close($hin); # ensure the flush | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | $pack->{cstream_data}{pid} = CORE::open($hout, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 3 | ▶ | "|$pack->{compress_method} > $pack->{cstream_data}{file_block}") or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $pack->{log}("Unable to start $pack->{compress_method}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 3 | $pack->{cstream_data}{hout} = $hout; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 3 | binmode $hout; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | # until we have data to push or data to read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | # pushing data to compressor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 369 | ▶ | (syswrite($hout, $$data)) == length($$data) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $pack->{log}("Can't push all data to compressor"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 369 | return 0; # We can't be sure about data really written in the pipe | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | # because of multitasking and buffer, so nothing has been | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | # written | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } elsif (defined($pack->{cstream_data})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | # If $data is not set, this mean we want a flush(), for end_block() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | close($hout); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 3 | waitpid $pack->{cstream_data}{pid}, 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | # copy temp bloc to archive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 3 | ▶ | sysopen(my $hin, $pack->{cstream_data}{file_block}, O_RDONLY) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $pack->{log}("Can't open temp block file: $!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 3 | unlink($pack->{cstream_data}{file_block}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 3 | ▶ | while (my $length = sysread($hin, my $tdata, $pack->{bufsize})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 348 | ▶ | (my $l = syswrite($pack->{handle}, $tdata)) == $length or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $pack->{log}("Can't write all data in archive"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 348 | $outsize += $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 3 | close($hin); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 3 | $pack->{cstream_data} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | # TODO current_block_csize isn't 0 ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | return $outsize - $pack->{current_block_csize} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 3 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 53 | ▶ | sub uncompress_handle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uncompress_handle: called CC=22 SCAR=36.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 53 | my ($pack, $destfh, $fileinfo) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 53 | ▶ | if (defined($pack->{ustream_data}) && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
defined $pack->{"ustream_data"} and !defined($fileinfo) || ($fileinfo->{"coff"} != $pack->{"ustream_data"}{"coff"} || $fileinfo->{"off"} < $pack->{"ustream_data"}{"off"})
not defined $fileinfo or ($fileinfo->{"coff"} != $pack->{"ustream_data"}{"coff"} or $fileinfo->{"off"} < $pack->{"ustream_data"}{"off"})
$fileinfo->{"coff"} != $pack->{"ustream_data"}{"coff"} or $fileinfo->{"off"} < $pack->{"ustream_data"}{"off"}
MC/DC50%2/4
defined $pack->{"ustream_data"} and !defined($fileinfo) || ($fileinfo->{"coff"} != $pack->{"ustream_data"}{"coff"} || $fileinfo->{"off"} < $pack->{"ustream_data"}{"off"})
defined $pack->{"ustream_data"}
not defined $fileinfo
$fileinfo->{"coff"} != $pack->{"ustream_data"}{"coff"}
$fileinfo->{"off"} < $pack->{"ustream_data"}{"off"}
Truth table60%3/5
A and not(B) or C or D
A= defined $pack->{"ustream_data"}B= not defined $fileinfoC= $fileinfo->{"coff"} != $pack->{"ustream_data"}{"coff"}D= $fileinfo->{"off"} < $pack->{"ustream_data"}{"off"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | !defined($fileinfo) || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | ($fileinfo->{coff} != $pack->{ustream_data}{coff} || $fileinfo->{off} < $pack->{ustream_data}{off}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | )) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 3 | close($pack->{ustream_data}{handle}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 3 | unlink($pack->{ustream_data}{tempname}); # deleting temp file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 3 | $pack->{ustream_data} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 53 | ▶ | defined($fileinfo) or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # We have to first extract the block to a temp file, burk ! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 45 | ▶ | if (!defined($pack->{ustream_data})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 3 | my $tempfh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 3 | $pack->{ustream_data}{coff} = $fileinfo->{coff}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 3 | $pack->{ustream_data}{read} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | ($tempfh, $pack->{ustream_data}{tempname}) = tempfile(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 3 | my $cread = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 3 | ▶ | while ($cread < $fileinfo->{csize}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | my $cl = sysread($pack->{handle}, my $data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | $cread + $pack->{bufsize} > $fileinfo->{csize} ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | $fileinfo->{csize} - $cread : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 348 | ▶ | $pack->{bufsize}) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | $pack->{log}("Unexpected end of file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | close($tempfh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | unlink($pack->{ustream_data}{tempname}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $pack->{ustream_data} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 348 | $cread += $cl; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 348 | ▶ | syswrite($tempfh, $data) == length($data) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $pack->{log}("Can't write all data into temp file"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | close($tempfh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | unlink($pack->{ustream_data}{tempname}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | $pack->{ustream_data} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 3 | close($tempfh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 3 | ▶ | my $cmd = $pack->{uncompress_method} eq 'gzip -d' || $pack->{uncompress_method} eq 'bzip2 -d' ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pack->{"uncompress_method"} eq "gzip -d" or $pack->{"uncompress_method"} eq "bzip2 -d"
MC/DC100%2/2
$pack->{"uncompress_method"} eq "gzip -d" or $pack->{"uncompress_method"} eq "bzip2 -d"
$pack->{"uncompress_method"} eq "gzip -d"
$pack->{"uncompress_method"} eq "bzip2 -d"
Truth table100%3/3
A or B
A= $pack->{"uncompress_method"} eq "gzip -d"B= $pack->{"uncompress_method"} eq "bzip2 -d"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | "$pack->{uncompress_method} -c '$pack->{ustream_data}{tempname}'" : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | "$pack->{uncompress_method} < '$pack->{ustream_data}{tempname}'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 3 | ▶ | CORE::open($pack->{ustream_data}{handle}, "$cmd |") or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $pack->{log}("Can't start $pack->{uncompress_method} to uncompress data"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | unlink($pack->{ustream_data}{tempname}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $pack->{ustream_data} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 3 | binmode($pack->{ustream_data}{handle}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 45 | my $byteswritten = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 45 | $pack->{ustream_data}{off} = $fileinfo->{off}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 45 | ▶ | while ($byteswritten < $fileinfo->{size}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 1244 | my $data = $pack->{ustream_data}{buf}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 1244 | $pack->{ustream_data}{buf} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1244 | my $length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 1244 | ▶ | if (!defined($data)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1205 | ▶ | $length = sysread($pack->{ustream_data}{handle}, $data, $pack->{bufsize}) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | $pack->{log}("Unexpected end of stream $pack->{ustream_data}{tempname}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | unlink($pack->{ustream_data}{tempname}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | close($pack->{ustream_data}{handle}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $pack->{ustream_data} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 39 | $length = length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 1244 | ▶ | if ($pack->{ustream_data}{read} < $fileinfo->{off} && $pack->{ustream_data}{read} + $length > $fileinfo->{off}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pack->{"ustream_data"}{"read"} < $fileinfo->{"off"} and $pack->{"ustream_data"}{"read"} + $length > $fileinfo->{"off"}
MC/DC0%0/2
$pack->{"ustream_data"}{"read"} < $fileinfo->{"off"} and $pack->{"ustream_data"}{"read"} + $length > $fileinfo->{"off"}
$pack->{"ustream_data"}{"read"} < $fileinfo->{"off"}
$pack->{"ustream_data"}{"read"} + $length > $fileinfo->{"off"}
Truth table33%1/3
A and B
A= $pack->{"ustream_data"}{"read"} < $fileinfo->{"off"}B= $pack->{"ustream_data"}{"read"} + $length > $fileinfo->{"off"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $data = substr($data, $fileinfo->{off} - $pack->{ustream_data}{read}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 1244 | $pack->{ustream_data}{read} += $length; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | if ($pack->{ustream_data}{read} <= $fileinfo->{off}) { next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 1244 | my $bw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1244 | ▶ | if ($byteswritten + length($data) > $fileinfo->{size}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 39 | $bw = $fileinfo->{size} - $byteswritten; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 39 | $pack->{ustream_data}{buf} = substr($data, $bw); # keeping track of unwritten uncompressed data | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 39 | $pack->{ustream_data}{read} -= length($pack->{ustream_data}{buf}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 1205 | $bw = length($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 1244 | ▶ | syswrite($destfh, $data, $bw) == $bw or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | $pack->{log}("Can't write data into dest"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 1244 | $byteswritten += $bw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | $byteswritten | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 45 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | ################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # Debug functions # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | ################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # This function extracts in $dest the whole block containing $file, can be useful for debugging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | ▶ | sub extract_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract_block: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | my ($pack, $dest, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | ▶ | sysopen(my $handle, $dest, O_WRONLY | O_TRUNC | O_CREAT) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | $pack->{log}("Can't open $dest: $!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | sysseek($pack->{handle}, $pack->{files}{$file}->{coff}, 0) == $pack->{files}{$file}->{coff} or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | $pack->{log}("Can't seek to offset $pack->{files}{$file}->{coff}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | close($handle); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | my $l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | $l = sysread($pack->{handle}, my $buf, $pack->{files}{$file}->{csize}) == $pack->{files}{$file}{csize} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | or $pack->{log}("Read only $l / $pack->{files}{$file}->{csize} bytes"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | syswrite($handle, $buf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | foreach ($pack->sort_files_by_packing(keys %{$pack->{files}})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | $pack->{files}{$_}{coff} == $pack->{files}{$file}->{coff} or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | close($handle); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | ################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # Really working functions # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | # Aka function people should use # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | ################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 68 | ▶ | sub add_virtual { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_virtual: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 68 | my ($pack, $type, $filename, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 68 | ▶ | $type eq 'l' and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 2 | $pack->{'symlink'}{$filename} = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 2 | $pack->{need_build_toc} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 66 | ▶ | $type eq 'd' and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 2 | $pack->{dir}{$filename}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 2 | $pack->{need_build_toc} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 64 | ▶ | $type eq 'f' and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | # Be sure we are at the end, allow extract + add in only one instance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 64 | ▶ | $pack->end_seek() or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $pack->{log}("Can't seek to offset $pack->{coff}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 64 | ▶ | my ($size, $csize) = (ref($data) eq 'GLOB') ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | $pack->compress_handle($data) : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | (length($data), $pack->compress_data($data)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | $pack->{current_block_files}{$filename} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | size => $size, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | off => $pack->{current_block_off}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | coff => $pack->{current_block_coff}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 64 | csize => -1, # Still unknown, will be fill by end_block | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | }; # Storing in toc structure availlable info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # Updating internal info about current block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 64 | $pack->{current_block_off} += $size; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 64 | $pack->{current_block_csize} += $csize; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 64 | $pack->{need_build_toc} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 64 | ▶ | if ($pack->{block_size} > 0 && $pack->{current_block_csize} >= $pack->{block_size}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pack->{"block_size"} > 0 and $pack->{"current_block_csize"} >= $pack->{"block_size"}
MC/DC50%1/2
$pack->{"block_size"} > 0 and $pack->{"current_block_csize"} >= $pack->{"block_size"}
$pack->{"block_size"} > 0
$pack->{"current_block_csize"} >= $pack->{"block_size"}
Truth table66%2/3
A and B
A= $pack->{"block_size"} > 0B= $pack->{"current_block_csize"} >= $pack->{"block_size"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 11 | $pack->end_block(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 64 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | 0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 4 | ▶ | sub add { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=8 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 4 | my ($pack, $prefix, @files) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 4 | ▶ | $prefix ||= ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$prefix ||= ""
MC/DC0%0/1
$prefix ||= ""
$prefix
Truth table50%1/2
A
A= $prefix
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 4 | foreach my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 60 | $file =~ s://+:/:; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 60 | ▶ | my $srcfile = $prefix ? "$prefix/$file" : $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 60 | $pack->{debug}("Adding '%s' as '%s' into archive", $srcfile, $file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 60 | ▶ | -l $srcfile and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | $pack->add_virtual('l', $file, readlink($srcfile)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 60 | ▶ | -d $srcfile and do { # dir simple case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | $pack->add_virtual('d', $file); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 60 | ▶ | -f $srcfile and do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 60 | ▶ | sysopen(my $htocompress, $srcfile, O_RDONLY) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | $pack->{log}("Can't add $srcfile: $!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 60 | $pack->add_virtual('f', $file, $htocompress); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 60 | close($htocompress); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 60 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | $pack->{log}("Can't pack $srcfile"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 64 | ▶ | sub extract_virtual { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract_virtual: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 64 | my ($pack, $destfh, $filename) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 64 | ▶ | defined($pack->{files}{$filename}) or return -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 64 | ▶ | sysseek($pack->{handle}, $pack->{files}{$filename}->{coff}, 0) == $pack->{files}{$filename}->{coff} or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $pack->{log}("Can't seek to offset $pack->{files}{$filename}->{coff}"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 64 | $pack->uncompress_handle($destfh, $pack->{files}{$filename}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 8 | ▶ | sub extract { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract: called CC=20 SCAR=38.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 8 | my ($pack, $destdir, @files) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 8 | foreach my $f ($pack->sort_files_by_packing(@files)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 64 | ▶ | my $dest = $destdir ? "$destdir/$f" : "$f"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 64 | my ($dir) = $dest =~ m!(.*)/.*!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 64 | ▶ | $dir ||= "."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$dir ||= "."
MC/DC0%0/1
$dir ||= "."
$dir
Truth table50%1/2
A
A= $dir
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 64 | ▶ | if (exists($pack->{dir}{$f})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | -d $dest || mkpath($dest) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 2 | ▶ | or $pack->{log}("Unable to create dir $dest: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $dest or mkpath($dest)
MC/DC0%0/2
-d $dest or mkpath($dest)
-d $dest
mkpath($dest)
Truth table33%1/3
A or B
A= -d $destB= mkpath($dest)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } elsif (exists($pack->{'symlink'}{$f})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | -d $dir || mkpath($dir) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 2 | ▶ | $pack->{log}("Unable to create dir $dest: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $dir or mkpath($dir)
MC/DC0%0/2
-d $dir or mkpath($dir)
-d $dir
mkpath($dir)
Truth table33%1/3
A or B
A= -d $dirB= mkpath($dir)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 2 | ▶ | -l $dest and unlink $dest; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | symlink($pack->{'symlink'}{$f}, $dest) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 2 | ▶ | or $pack->{log}("Unable to extract symlink $f: $!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } elsif (exists($pack->{files}{$f})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 60 | ▶ | -d $dir || mkpath($dir) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $dir or mkpath($dir)
MC/DC0%0/2
-d $dir or mkpath($dir)
-d $dir
mkpath($dir)
Truth table33%1/3
A or B
A= -d $dirB= mkpath($dir)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | $pack->{log}("Unable to create dir $dir"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 60 | ▶ | if (-l $dest) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | ▶ | unlink($dest) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | $pack->{log}("Can't remove link $dest: $!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | next; # Don't overwrite a file because where the symlink point to | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 60 | my $destfh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 60 | ▶ | if (defined $destdir) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 60 | ▶ | sysopen($destfh, $dest, O_CREAT | O_TRUNC | O_WRONLY) or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | $pack->{log}("Unable to extract $dest: $!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | $destfh = \*STDOUT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 60 | my $written = $pack->extract_virtual($destfh, $f); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 60 | ▶ | $written == -1 and $pack->{log}("Unable to extract file $f"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 60 | close($destfh); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 60 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | $pack->{log}("Can't find $f in archive"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | # Return \@dir, \@files, \@symlink list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 0 | ▶ | sub getcontent { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getcontent: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | my ($pack) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | return( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | [ keys(%{$pack->{dir}})], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | [ $pack->sort_files_by_packing(keys %{$pack->{files}}) ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | [ keys(%{$pack->{'symlink'}}) ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 8 | ▶ | sub infofile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
infofile: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 8 | my ($pack, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 8 | ▶ | if (defined($pack->{files}{$file})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 2 | return ('f', $pack->{files}{$file}{size}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } elsif (defined($pack->{'symlink'}{$file})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 2 | return ('l', $pack->{'symlink'}{$file}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } elsif (defined($pack->{dir}{$file})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 2 | return ('d', undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 2 | return(undef, undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | sub list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | my ($pack, $handle) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | ▶ | $handle ||= *STDOUT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$handle ||= *STDOUT
MC/DC0%0/2
$handle ||= *STDOUT
$handle
*STDOUT
Truth table0%0/3
A ||= B
A= $handleB= *STDOUT
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | foreach my $file (keys %{$pack->{dir}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | printf "d %13c %s\n", ' ', $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | foreach my $file (keys %{$pack->{'symlink'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | printf "l %13c %s -> %s\n", ' ', $file, $pack->{'symlink'}{$file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 0 | foreach my $file ($pack->sort_files_by_packing(keys %{$pack->{files}})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | printf "f %12d %s\n", $pack->{files}{$file}{size}, $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # Print toc info | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | ▶ | sub dumptoc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dumptoc: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | my ($pack, $handle) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | $handle ||= *STDOUT; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$handle ||= *STDOUT
MC/DC0%0/2
$handle ||= *STDOUT
$handle
*STDOUT
Truth table0%0/3
A ||= B
A= $handleB= *STDOUT
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | foreach my $file (keys %{$pack->{dir}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | printf $handle "d %13c %s\n", ' ', $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | foreach my $file (keys %{$pack->{'symlink'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | printf $handle "l %13c %s -> %s\n", ' ', $file, $pack->{'symlink'}{$file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | foreach my $file ($pack->sort_files_by_packing(keys %{$pack->{files}})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | printf $handle "f %d %d %d %d %s\n", $pack->{files}{$file}{size}, $pack->{files}{$file}{off}, $pack->{files}{$file}{csize}, $pack->{files}{$file}{coff}, $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||