blib/lib/IO/Compress/Zip.pm

filter: Statementstmt 85.2% 375 / 440 Branchbran 61.2% 114 / 186 Conditioncond 46.0% 29 / 63 MC/DCmcdc 24.3% 9 / 37 Subroutinesub 91.4% 32 / 35 Podpod 10.5% 2 / 19 totaltotal 71.9% 561 / 780 CC 117 SCAR 35.5
CC
117
Cov
75%
ckParams
115.9
isMethodAvailable
43.1
mkHeader
32.2
CRAP 34.9
« blib/lib/IO/Uncompress/Unzip.pm ↑ Summary blib/lib/IO/Uncompress/Gunzip.pm »
1 package IO::Compress::Zip ;
2  
3 47 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 47 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 47 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 47 ▶use IO::Compress::Base::Common 2.225 qw(:Status );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 47 ▶use IO::Compress::RawDeflate 2.225 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 47 ▶use IO::Compress::Adapter::Deflate 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 47 ▶use IO::Compress::Adapter::Identity 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 47 ▶use IO::Compress::Zlib::Extra 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 47 ▶use IO::Compress::Zip::Constants 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 47 ▶use File::Spec();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 47 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 47 ▶use Compress::Raw::Zlib 2.225 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 BEGIN
20 47 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.9
21 47 eval { require IO::Compress::Adapter::Bzip2 ;
22 47 IO::Compress::Adapter::Bzip2->VERSION( 2.225 );
23 47 require IO::Compress::Bzip2 ;
24 47 IO::Compress::Bzip2->VERSION( 2.225 );
25 } ;
26  
27 47 eval { require IO::Compress::Adapter::Lzma ;
28 0 IO::Compress::Adapter::Lzma->VERSION( 2.225 );
29 0 require IO::Compress::Lzma ;
30 0 IO::Compress::Lzma->VERSION( 2.225 );
31 } ;
32  
33 47 eval { require IO::Compress::Adapter::Xz ;
34 0 IO::Compress::Adapter::Xz->VERSION( 2.225 );
35 0 require IO::Compress::Xz ;
36 0 IO::Compress::Xz->VERSION( 2.225 );
37 } ;
38 47 eval { require IO::Compress::Adapter::Zstd ;
39 0 IO::Compress::Adapter::Zstd->VERSION( 2.225 );
40 0 require IO::Compress::Zstd ;
41 0 IO::Compress::Zstd->VERSION( 2.225 );
42 } ;
43 }
44  
45  
46 47 require Exporter ;
47  
48 47 our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $ZipError);
49  
50 47 $VERSION = '2.225';
51 47 $ZipError = '';
52  
53 47 @ISA = qw(IO::Compress::RawDeflate Exporter);
54 47 @EXPORT_OK = qw( $ZipError zip ) ;
55 47 %EXPORT_TAGS = %IO::Compress::RawDeflate::DEFLATE_CONSTANTS ;
56  
57 47 my @zip_methods = qw( ZIP_CM_STORE ZIP_CM_DEFLATE ZIP_CM_BZIP2 ZIP_CM_LZMA ZIP_CM_XZ ZIP_CM_ZSTD ) ;
58 47 ▶$EXPORT_TAGS{all} = [ defined $EXPORT_TAGS{all} ? @{ $EXPORT_TAGS{all} } : (), @EXPORT_OK, @zip_methods ] ;
Branch: 1 branch
BranchTrueFalseTotal
defined $IO::Compress::Zip::EXPORT_TAGS{'all'} ? : 47 0 47
59  
60 47 $EXPORT_TAGS{zip_method} = [ @zip_methods ];
61 47 push @{ $EXPORT_TAGS{constants} }, @zip_methods ;
62  
63 47 Exporter::export_ok_tags('all');
64  
65 sub new
66 151 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
67 151 my $class = shift ;
68  
69 151 my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$ZipError);
70 151 $obj->_create(undef, @_);
71  
72 }
73  
74 sub zip
75 225 ▶{
Subroutine zip: called CC=1 SCAR=0.0
Pod documented
76 225 my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$ZipError);
77 225 return $obj->_def(@_);
78 }
79  
80 sub isMethodAvailable
81 3 ▶{
Subroutine isMethodAvailable: called CC=15 SCAR=37.6
Pod undocumented
82 3 my $method = shift;
83  
84 # Store & Deflate are always available
85 3 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if $method == 0 or $method == 8 2 1 3
Condition100%3/3
$method == 0 or $method == 8
l!l&&r!l&&!r
111
MC/DC100%2/2
$method == 0 or $method == 8
$method == 0 $method == 8
Truth table100%3/3
A or B
A= $method == 0B= $method == 8
ABresult
1X1
011
000
86 if $method == ZIP_CM_STORE || $method == ZIP_CM_DEFLATE ;
87  
88 return 1
89 if $method == ZIP_CM_BZIP2 &&
90 defined $IO::Compress::Adapter::Bzip2::VERSION &&
91 0 ▶ defined &{ "IO::Compress::Adapter::Bzip2::mkRawZipCompObject" };
Branch: 1 branch
BranchTrueFalseTotal
if $method == 12 and defined $IO::Compress::Adapter::Bzip2::VERSION and defined &{"IO::Compress::Adapter::Bzip2::mkRawZipCompObject";} 0 1 1
Condition33%2/6
$method == 12 and defined $IO::Compress::Adapter::Bzip2::VERSION and defined &{"IO::Compress::Adapter::Bzip2::mkRawZipCompObject";}
!ll&&!rl&&r
100
$method == 12 and defined $IO::Compress::Adapter::Bzip2::VERSION
!ll&&!rl&&r
100
MC/DC0%0/3
$method == 12 and defined $IO::Compress::Adapter::Bzip2::VERSION and defined &{"IO::Compress::Adapter::Bzip2::mkRawZipCompObject";}
$method == 12 defined $IO::Compress::Adapter::Bzip2::VERSION defined &{"IO::Compress::Adapter::Bzip2::mkRawZipCompObject";}
Truth table25%1/4
A and B and C
A= $method == 12B= defined $IO::Compress::Adapter::Bzip2::VERSIONC= defined &{"IO::Compress::Adapter::Bzip2::mkRawZipCompObject";}
ABCresult
0XX0
10X0
1100
1111
92  
93 return 1
94 if $method == ZIP_CM_LZMA &&
95 defined $IO::Compress::Adapter::Lzma::VERSION &&
96 0 ▶ defined &{ "IO::Compress::Adapter::Lzma::mkRawZipCompObject" };
Branch: 1 branch
BranchTrueFalseTotal
if $method == 14 and defined $IO::Compress::Adapter::Lzma::VERSION and defined &{"IO::Compress::Adapter::Lzma::mkRawZipCompObject";} 0 1 1
Condition33%2/6
$method == 14 and defined $IO::Compress::Adapter::Lzma::VERSION and defined &{"IO::Compress::Adapter::Lzma::mkRawZipCompObject";}
!ll&&!rl&&r
100
$method == 14 and defined $IO::Compress::Adapter::Lzma::VERSION
!ll&&!rl&&r
100
MC/DC0%0/3
$method == 14 and defined $IO::Compress::Adapter::Lzma::VERSION and defined &{"IO::Compress::Adapter::Lzma::mkRawZipCompObject";}
$method == 14 defined $IO::Compress::Adapter::Lzma::VERSION defined &{"IO::Compress::Adapter::Lzma::mkRawZipCompObject";}
Truth table25%1/4
A and B and C
A= $method == 14B= defined $IO::Compress::Adapter::Lzma::VERSIONC= defined &{"IO::Compress::Adapter::Lzma::mkRawZipCompObject";}
ABCresult
0XX0
10X0
1100
1111
97  
98 return 1
99 if $method == ZIP_CM_XZ &&
100 defined $IO::Compress::Adapter::Xz::VERSION &&
101 0 ▶ defined &{ "IO::Compress::Adapter::Xz::mkRawZipCompObject" };
Branch: 1 branch
BranchTrueFalseTotal
if $method == 95 and defined $IO::Compress::Adapter::Xz::VERSION and defined &{"IO::Compress::Adapter::Xz::mkRawZipCompObject";} 0 1 1
Condition33%2/6
$method == 95 and defined $IO::Compress::Adapter::Xz::VERSION and defined &{"IO::Compress::Adapter::Xz::mkRawZipCompObject";}
!ll&&!rl&&r
100
$method == 95 and defined $IO::Compress::Adapter::Xz::VERSION
!ll&&!rl&&r
100
MC/DC0%0/3
$method == 95 and defined $IO::Compress::Adapter::Xz::VERSION and defined &{"IO::Compress::Adapter::Xz::mkRawZipCompObject";}
$method == 95 defined $IO::Compress::Adapter::Xz::VERSION defined &{"IO::Compress::Adapter::Xz::mkRawZipCompObject";}
Truth table25%1/4
A and B and C
A= $method == 95B= defined $IO::Compress::Adapter::Xz::VERSIONC= defined &{"IO::Compress::Adapter::Xz::mkRawZipCompObject";}
ABCresult
0XX0
10X0
1100
1111
102  
103 return 1
104 if $method == ZIP_CM_ZSTD &&
105 defined $IO::Compress::Adapter::ZSTD::VERSION &&
106 0 ▶ defined &{ "IO::Compress::Adapter::ZSTD::mkRawZipCompObject" };
Branch: 1 branch
BranchTrueFalseTotal
if $method == 93 and defined $IO::Compress::Adapter::ZSTD::VERSION and defined &{"IO::Compress::Adapter::ZSTD::mkRawZipCompObject";} 0 1 1
Condition33%2/6
$method == 93 and defined $IO::Compress::Adapter::ZSTD::VERSION and defined &{"IO::Compress::Adapter::ZSTD::mkRawZipCompObject";}
!ll&&!rl&&r
100
$method == 93 and defined $IO::Compress::Adapter::ZSTD::VERSION
!ll&&!rl&&r
100
MC/DC0%0/3
$method == 93 and defined $IO::Compress::Adapter::ZSTD::VERSION and defined &{"IO::Compress::Adapter::ZSTD::mkRawZipCompObject";}
$method == 93 defined $IO::Compress::Adapter::ZSTD::VERSION defined &{"IO::Compress::Adapter::ZSTD::mkRawZipCompObject";}
Truth table25%1/4
A and B and C
A= $method == 93B= defined $IO::Compress::Adapter::ZSTD::VERSIONC= defined &{"IO::Compress::Adapter::ZSTD::mkRawZipCompObject";}
ABCresult
0XX0
10X0
1100
1111
107  
108 1 return 0;
109 }
110  
111 sub beforePayload
112 411 ▶{
Subroutine beforePayload: called CC=4 SCAR=24.6
Pod undocumented
113 411 my $self = shift ;
114  
115 411 ▶ if (*$self->{ZipData}{Sparse} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"ZipData"}{"Sparse"}) 0 411 411
116 0 my $inc = 1024 * 100 ;
117 0 my $NULLS = ("\x00" x $inc) ;
118 0 my $sparse = *$self->{ZipData}{Sparse} ;
119 0 *$self->{CompSize}->add( $sparse );
120 0 *$self->{UnCompSize}->add( $sparse );
121  
122 0 *$self->{FH}->seek($sparse, IO::Handle::SEEK_CUR);
123  
124 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32($NULLS, *$self->{ZipData}{CRC32})
125 0 for 1 .. int $sparse / $inc;
126 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32(substr($NULLS, 0, $sparse % $inc),
127 *$self->{ZipData}{CRC32})
128 0 ▶ if $sparse % $inc;
Branch: 1 branch
BranchTrueFalseTotal
if $sparse % $inc 0 0 0
129 }
130 }
131  
132 sub mkComp
133 413 ▶{
Subroutine mkComp: called CC=11 SCAR=29.0
Pod undocumented
134 413 my $self = shift ;
135 413 my $got = shift ;
136  
137 413 my ($obj, $errstr, $errno) ;
138  
139 413 ▶ if (*$self->{ZipData}{Method} == ZIP_CM_STORE) {
Branch: 6 branches
BranchTrueFalseTotal
if (*$self->{'ZipData'}{'Method'} == 0) { } 36 377 413
elsif (*$self->{'ZipData'}{'Method'} == 8) { } 356 21 377
elsif (*$self->{'ZipData'}{'Method'} == 12) { } 21 0 21
elsif (*$self->{'ZipData'}{'Method'} == 14) { } 0 0 0
elsif (*$self->{'ZipData'}{'Method'} == 95) { } 0 0 0
elsif (*$self->{'ZipData'}{'Method'} == 93) { } 0 0 0
140 36 ($obj, $errstr, $errno) = IO::Compress::Adapter::Identity::mkCompObject(
141 $got->getValue('level'),
142 $got->getValue('strategy')
143 );
144 36 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32(undef);
145 }
146 elsif (*$self->{ZipData}{Method} == ZIP_CM_DEFLATE) {
147 356 ($obj, $errstr, $errno) = IO::Compress::Adapter::Deflate::mkCompObject(
148 $got->getValue('crc32'),
149 $got->getValue('adler32'),
150 $got->getValue('level'),
151 $got->getValue('strategy')
152 );
153 }
154 elsif (*$self->{ZipData}{Method} == ZIP_CM_BZIP2) {
155 21 ($obj, $errstr, $errno) = IO::Compress::Adapter::Bzip2::mkCompObject(
156 $got->getValue('blocksize100k'),
157 $got->getValue('workfactor'),
158 $got->getValue('verbosity')
159 );
160 21 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32(undef);
161 }
162 elsif (*$self->{ZipData}{Method} == ZIP_CM_LZMA) {
163 0 ($obj, $errstr, $errno) = IO::Compress::Adapter::Lzma::mkRawZipCompObject($got->getValue('preset'),
164 $got->getValue('extreme'),
165 );
166 0 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32(undef);
167 }
168 elsif (*$self->{ZipData}{Method} == ZIP_CM_XZ) {
169 0 ($obj, $errstr, $errno) = IO::Compress::Adapter::Xz::mkCompObject($got->getValue('preset'),
170 $got->getValue('extreme'),
171 0
172 );
173 0 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32(undef);
174 }
175 elsif (*$self->{ZipData}{Method} == ZIP_CM_ZSTD) {
176 0 ▶ ($obj, $errstr, $errno) = IO::Compress::Adapter::Zstd::mkCompObject(defined $got->getValue('level') ? $got->getValue('level') : 3,
Branch: 1 branch
BranchTrueFalseTotal
defined $got->getValue('level') ? : 0 0 0
177 );
178 0 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32(undef);
179 }
180  
181 413 ▶ return $self->saveErrorString(undef, $errstr, $errno)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 0 413 413
182 if ! defined $obj;
183  
184 413 ▶ if (! defined *$self->{ZipData}{SizesOffset}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined *$self->{"ZipData"}{"SizesOffset"}) 342 71 413
185 342 *$self->{ZipData}{SizesOffset} = 0;
186 342 *$self->{ZipData}{Offset} = U64->new();
187 }
188  
189 *$self->{ZipData}{AnyZip64} = 0
190 413 ▶ if ! defined *$self->{ZipData}{AnyZip64} ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined *$self->{"ZipData"}{"AnyZip64"} 321 92 413
191  
192 413 return $obj;
193 }
194  
195 sub reset
196 0 ▶{
Subroutine reset: not called CC=1 SCAR=6.9
Pod undocumented
197 0 my $self = shift ;
198  
199 0 *$self->{Compress}->reset();
200 0 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32('');
201  
202 0 return STATUS_OK;
203 }
204  
205 sub filterUncompressed
206 393 ▶{
Subroutine filterUncompressed: called CC=2 SCAR=6.9
Pod undocumented
207 393 my $self = shift ;
208  
209 393 ▶ if (*$self->{ZipData}{Method} == ZIP_CM_DEFLATE) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'ZipData'}{'Method'} == 8) { } 341 52 393
210 341 *$self->{ZipData}{CRC32} = *$self->{Compress}->crc32();
211 }
212 else {
213 52 *$self->{ZipData}{CRC32} = Compress::Raw::Zlib::crc32(${$_[0]}, *$self->{ZipData}{CRC32});
214  
215 }
216 }
217  
218 sub canonicalName
219 2 ▶{
Subroutine canonicalName: called CC=4 SCAR=14.0
Pod undocumented
220 # This sub is derived from Archive::Zip::_asZipDirName
221  
222 # Return the normalized name as used in a zip file (path
223 # separators become slashes, etc.).
224 # Will translate internal slashes in path components (i.e. on Macs) to
225 # underscores. Discards volume names.
226 # When $forceDir is set, returns paths with trailing slashes
227 #
228 # input output
229 # . '.'
230 # ./a a
231 # ./a/b a/b
232 # ./a/b/ a/b
233 # a/b/ a/b
234 # /a/b/ a/b
235 # c:\a\b\c.doc a/b/c.doc # on Windows
236 # "i/o maps:whatever" i_o maps/whatever # on Macs
237  
238 2 my $name = shift;
239 2 my $forceDir = shift ;
240  
241 2 my ( $volume, $directories, $file ) =
242 File::Spec->splitpath( File::Spec->canonpath($name), $forceDir );
243  
244 2 my @dirs = map { $_ =~ s{/}{_}g; $_ }
245 File::Spec->splitdir($directories);
246  
247 2 ▶ if ( @dirs > 0 ) { pop (@dirs) if $dirs[-1] eq '' } # remove empty component
Branch: 2 branches
BranchTrueFalseTotal
if (@dirs > 0) 2 0 2
if $dirs[-1] eq "" 2 0 2
248 2 ▶ push @dirs, defined($file) ? $file : '' ;
Branch: 1 branch
BranchTrueFalseTotal
defined $file ? : 2 0 2
249  
250 2 my $normalised_path = join '/', @dirs;
251  
252 # Leading directory separators should not be stored in zip archives.
253 # Example:
254 # C:\a\b\c\ a/b/c
255 # C:\a\b\c.txt a/b/c.txt
256 # /a/b/c/ a/b/c
257 # /a/b/c.txt a/b/c.txt
258 2 $normalised_path =~ s{^/}{}; # remove leading separator
259  
260 2 return $normalised_path;
261 }
262  
263  
264 sub mkHeader
265 412 ▶{
Subroutine mkHeader: called CC=30 SCAR=34.7
Pod undocumented
266 412 my $self = shift;
267 412 my $param = shift ;
268  
269 412 *$self->{ZipData}{LocalHdrOffset} = U64::clone(*$self->{ZipData}{Offset});
270  
271 412 my $comment = '';
272 412 $comment = $param->valueOrDefault('comment') ;
273  
274 412 my $filename = '';
275 412 $filename = $param->valueOrDefault('name') ;
276  
277 412 ▶ $filename = canonicalName($filename)
Branch: 1 branch
BranchTrueFalseTotal
if length $filename and $param->getValue("canonicalname") 2 410 412
Condition100%3/3
length $filename and $param->getValue("canonicalname")
!ll&&!rl&&r
2291812
MC/DC100%2/2
length $filename and $param->getValue("canonicalname")
length $filename $param->getValue("canonicalname")
Truth table100%3/3
A and B
A= length $filenameB= $param->getValue("canonicalname")
ABresult
0X0
100
111
278 if length $filename && $param->getValue('canonicalname') ;
279  
280 412 ▶ if (defined *$self->{ZipData}{FilterName} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined *$self->{"ZipData"}{"FilterName"}) 3 409 412
281 3 local *_ = \$filename ;
282 3 &{ *$self->{ZipData}{FilterName} }() ;
283 }
284  
285 412 ▶ if ( $param->getValue('efs') && $] >= 5.008004) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->getValue("efs") and $] >= "5.008004") 5 407 412
Condition66%2/3
$param->getValue("efs") and $] >= "5.008004"
!ll&&!rl&&r
40705
MC/DC50%1/2
$param->getValue("efs") and $] >= "5.008004"
$param->getValue("efs") $] >= "5.008004"
Truth table66%2/3
A and B
A= $param->getValue("efs")B= $] >= "5.008004"
ABresult
0X0
100
111
286 5 ▶ if (length $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $filename) 5 0 5
287 5 ▶ utf8::downgrade($filename, 1)
Branch: 1 branch
BranchTrueFalseTotal
utf8::downgrade($filename, 1) or Carp::croak("Wide character in zip filename") 4 1 5
288 or Carp::croak "Wide character in zip filename";
289 }
290  
291 4 ▶ if (length $comment) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $comment) 0 4 4
292 0 ▶ utf8::downgrade($comment, 1)
Branch: 1 branch
BranchTrueFalseTotal
utf8::downgrade($comment, 1) or Carp::croak("Wide character in zip comment") 0 0 0
293 or Carp::croak "Wide character in zip comment";
294 }
295 }
296  
297 411 my $hdr = '';
298  
299 411 my $time = _unixToDosTime($param->getValue('time'));
300  
301 411 my $extra = '';
302 411 my $ctlExtra = '';
303 411 my $empty = 0;
304 411 my $osCode = $param->getValue('os_code') ;
305 411 my $extFileAttr = 0 ;
306  
307 # This code assumes Unix.
308 # TODO - revisit this
309 411 ▶ $extFileAttr = 0100644 << 16
Branch: 1 branch
BranchTrueFalseTotal
if $osCode == 3 411 0 411
310 if $osCode == ZIP_OS_CODE_UNIX ;
311  
312 411 ▶ if (*$self->{ZipData}{Zip64}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"ZipData"}{"Zip64"}) 26 385 411
313 26 $empty = IO::Compress::Base::Common::MAX32;
314  
315 26 my $x = '';
316 26 $x .= pack "V V", 0, 0 ; # uncompressedLength
317 26 $x .= pack "V V", 0, 0 ; # compressedLength
318  
319 # Zip64 needs to be first in extra field to workaround a Windows Explorer Bug
320 # See http://www.info-zip.org/phpBB3/viewtopic.php?f=3&t=440 for details
321 26 $extra .= IO::Compress::Zlib::Extra::mkSubField(ZIP_EXTRA_ID_ZIP64, $x);
322 }
323  
324 411 ▶ if (! $param->getValue('minimal')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($param->getValue("minimal")) 411 0 411
325 411 ▶ if ($param->parsed('mtime'))
Branch: 1 branch
BranchTrueFalseTotal
if ($param->parsed("mtime")) 113 298 411
326 {
327 113 $extra .= mkExtendedTime($param->getValue('mtime'),
328 $param->getValue('atime'),
329 $param->getValue('ctime'));
330  
331 113 $ctlExtra .= mkExtendedTime($param->getValue('mtime'));
332 }
333  
334 411 ▶ if ( $osCode == ZIP_OS_CODE_UNIX )
Branch: 1 branch
BranchTrueFalseTotal
if ($osCode == 3) 411 0 411
335 {
336 411 ▶ if ( $param->getValue('want_exunixn') )
Branch: 1 branch
BranchTrueFalseTotal
if ($param->getValue("want_exunixn")) 113 298 411
337 {
338 113 my $ux3 = mkUnixNExtra( @{ $param->getValue('want_exunixn') });
339 113 $extra .= $ux3;
340 113 $ctlExtra .= $ux3;
341 }
342  
343 411 ▶ if ( $param->getValue('exunix2') )
Branch: 1 branch
BranchTrueFalseTotal
if ($param->getValue("exunix2")) 0 411 411
344 {
345 0 $extra .= mkUnix2Extra( @{ $param->getValue('exunix2') });
346 0 $ctlExtra .= mkUnix2Extra();
347 }
348 }
349  
350 411 ▶ $extFileAttr = $param->getValue('extattr')
Branch: 1 branch
BranchTrueFalseTotal
if defined $param->getValue("extattr") 411 0 411
351 if defined $param->getValue('extattr') ;
352  
353 411 ▶ $extra .= $param->getValue('extrafieldlocal')
Branch: 1 branch
BranchTrueFalseTotal
if defined $param->getValue("extrafieldlocal") 0 411 411
354 if defined $param->getValue('extrafieldlocal');
355  
356 411 ▶ $ctlExtra .= $param->getValue('extrafieldcentral')
Branch: 1 branch
BranchTrueFalseTotal
if defined $param->getValue("extrafieldcentral") 0 411 411
357 if defined $param->getValue('extrafieldcentral');
358 }
359  
360 411 my $method = *$self->{ZipData}{Method} ;
361 411 my $gpFlag = 0 ;
362 $gpFlag |= ZIP_GP_FLAG_STREAMING_MASK
363 411 ▶ if *$self->{ZipData}{Stream} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"ZipData"}{"Stream"} 346 65 411
364  
365 411 ▶ $gpFlag |= ZIP_GP_FLAG_LZMA_EOS_PRESENT
Branch: 1 branch
BranchTrueFalseTotal
if $method == 14 0 411 411
366 if $method == ZIP_CM_LZMA ;
367  
368 411 ▶ $gpFlag |= ZIP_GP_FLAG_LANGUAGE_ENCODING
Branch: 1 branch
BranchTrueFalseTotal
if $param->getValue("efs") and length $filename || length $comment 4 407 411
Condition50%3/6
$param->getValue("efs") and length $filename || length $comment
!ll&&!rl&&r
40704
length $filename or length $comment
l!l&&r!l&&!r
400
MC/DC33%1/3
$param->getValue("efs") and length $filename || length $comment
$param->getValue("efs") length $filename length $comment
Truth table50%2/4
A and B or C
A= $param->getValue("efs")B= length $filenameC= length $comment
ABCresult
0XX0
1000
11X1
1011
369 if $param->getValue('efs') && (length($filename) || length($comment));
370  
371 411 my $version = $ZIP_CM_MIN_VERSIONS{$method};
372 $version = ZIP64_MIN_VERSION
373 411 ▶ if ZIP64_MIN_VERSION > $version && *$self->{ZipData}{Zip64};
Branch: 1 branch
BranchTrueFalseTotal
if 45 > $version and *$self->{"ZipData"}{"Zip64"} 20 391 411
Condition100%3/3
45 > $version and *$self->{"ZipData"}{"Zip64"}
!ll&&!rl&&r
2137020
MC/DC100%2/2
45 > $version and *$self->{"ZipData"}{"Zip64"}
45 > $version *$self->{"ZipData"}{"Zip64"}
Truth table100%3/3
A and B
A= 45 > $versionB= *$self->{"ZipData"}{"Zip64"}
ABresult
0X0
100
111
374  
375 411 my $madeBy = ($param->getValue('os_code') << 8) + $version;
376 411 my $extract = $version;
377  
378 411 *$self->{ZipData}{Version} = $version;
379 411 *$self->{ZipData}{MadeBy} = $madeBy;
380  
381 411 my $ifa = 0;
382 411 ▶ $ifa |= ZIP_IFA_TEXT_MASK
Branch: 1 branch
BranchTrueFalseTotal
if $param->getValue("textflag") 112 299 411
383 if $param->getValue('textflag');
384  
385 411 $hdr .= pack "V", ZIP_LOCAL_HDR_SIG ; # signature
386 411 $hdr .= pack 'v', $extract ; # extract Version & OS
387 411 $hdr .= pack 'v', $gpFlag ; # general purpose flag (set streaming mode)
388 411 $hdr .= pack 'v', $method ; # compression method (deflate)
389 411 $hdr .= pack 'V', $time ; # last mod date/time
390 411 $hdr .= pack 'V', 0 ; # crc32 - 0 when streaming
391 411 $hdr .= pack 'V', $empty ; # compressed length - 0 when streaming
392 411 $hdr .= pack 'V', $empty ; # uncompressed length - 0 when streaming
393 411 $hdr .= pack 'v', length $filename ; # filename length
394 411 $hdr .= pack 'v', length $extra ; # extra length
395  
396 411 $hdr .= $filename ;
397  
398 # Remember the offset for the compressed & uncompressed lengths in the
399 # local header.
400 411 ▶ if (*$self->{ZipData}{Zip64}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'ZipData'}{'Zip64'}) { } 26 385 411
401 *$self->{ZipData}{SizesOffset} = *$self->{ZipData}{Offset}->get64bit()
402 26 + length($hdr) + 4 ;
403 }
404 else {
405 *$self->{ZipData}{SizesOffset} = *$self->{ZipData}{Offset}->get64bit()
406 385 + 18;
407 }
408  
409 411 $hdr .= $extra ;
410  
411  
412 411 my $ctl = '';
413  
414 411 $ctl .= pack "V", ZIP_CENTRAL_HDR_SIG ; # signature
415 411 $ctl .= pack 'v', $madeBy ; # version made by
416 411 $ctl .= pack 'v', $extract ; # extract Version
417 411 $ctl .= pack 'v', $gpFlag ; # general purpose flag (streaming mode)
418 411 $ctl .= pack 'v', $method ; # compression method (deflate)
419 411 $ctl .= pack 'V', $time ; # last mod date/time
420 411 $ctl .= pack 'V', 0 ; # crc32
421 411 $ctl .= pack 'V', $empty ; # compressed length
422 411 $ctl .= pack 'V', $empty ; # uncompressed length
423 411 $ctl .= pack 'v', length $filename ; # filename length
424  
425 411 *$self->{ZipData}{ExtraOffset} = length $ctl;
426 411 *$self->{ZipData}{ExtraSize} = length $ctlExtra ;
427  
428 411 $ctl .= pack 'v', length $ctlExtra ; # extra length
429 411 $ctl .= pack 'v', length $comment ; # file comment length
430 411 $ctl .= pack 'v', 0 ; # disk number start
431 411 $ctl .= pack 'v', $ifa ; # internal file attributes
432 411 $ctl .= pack 'V', $extFileAttr ; # external file attributes
433  
434 # offset to local hdr
435 411 ▶ if (*$self->{ZipData}{LocalHdrOffset}->is64bit() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'ZipData'}{'LocalHdrOffset'}->is64bit) { } 0 411 411
436 0 $ctl .= pack 'V', IO::Compress::Base::Common::MAX32 ;
437 }
438 else {
439 411 $ctl .= *$self->{ZipData}{LocalHdrOffset}->getPacked_V32() ;
440 }
441  
442 411 $ctl .= $filename ;
443  
444 411 *$self->{ZipData}{Offset}->add32(length $hdr) ;
445  
446 411 *$self->{ZipData}{CentralHeader} = [ $ctl, $ctlExtra, $comment];
447  
448 411 return $hdr;
449 }
450  
451 sub mkTrailer
452 411 ▶{
Subroutine mkTrailer: called CC=11 SCAR=24.6
Pod undocumented
453 411 my $self = shift ;
454  
455 411 my $crc32 ;
456 411 ▶ if (*$self->{ZipData}{Method} == ZIP_CM_DEFLATE) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'ZipData'}{'Method'} == 8) { } 354 57 411
457 354 $crc32 = pack "V", *$self->{Compress}->crc32();
458 }
459 else {
460 57 $crc32 = pack "V", *$self->{ZipData}{CRC32};
461 }
462  
463 411 my ($ctl, $ctlExtra, $comment) = @{ *$self->{ZipData}{CentralHeader} };
464  
465 411 my $sizes ;
466 411 ▶ if (! *$self->{ZipData}{Zip64}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not *$self->{'ZipData'}{'Zip64'}) { } 385 26 411
467 385 $sizes .= *$self->{CompSize}->getPacked_V32() ; # Compressed size
468 385 $sizes .= *$self->{UnCompSize}->getPacked_V32() ; # Uncompressed size
469 }
470 else {
471 26 $sizes .= *$self->{CompSize}->getPacked_V64() ; # Compressed size
472 26 $sizes .= *$self->{UnCompSize}->getPacked_V64() ; # Uncompressed size
473 }
474  
475 411 my $data = $crc32 . $sizes ;
476  
477 411 my $xtrasize = *$self->{UnCompSize}->getPacked_V64() ; # Uncompressed size
478 411 $xtrasize .= *$self->{CompSize}->getPacked_V64() ; # Compressed size
479  
480 411 my $hdr = '';
481  
482 411 ▶ if (*$self->{ZipData}{Stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'ZipData'}{'Stream'}) { } 346 65 411
483 346 $hdr = pack "V", ZIP_DATA_HDR_SIG ; # signature
484 346 $hdr .= $data ;
485 }
486 else {
487 65 ▶ $self->writeAt(*$self->{ZipData}{LocalHdrOffset}->get64bit() + 14, $crc32)
Branch: 1 branch
BranchTrueFalseTotal
$self->writeAt(*$self->{"ZipData"}{"LocalHdrOffset"}->get64bit + 14, $crc32) or return undef 65 0 65
488 or return undef;
489 $self->writeAt(*$self->{ZipData}{SizesOffset},
490 65 ▶ *$self->{ZipData}{Zip64} ? $xtrasize : $sizes)
Branch: 2 branches
BranchTrueFalseTotal
$self->writeAt(*$self->{"ZipData"}{"SizesOffset"}, *$self->{"ZipData"}{"Zip64"} ? $xtrasize : $sizes) or return undef 65 0 65
*$self->{'ZipData'}{'Zip64'} ? : 8 57 65
491 or return undef;
492 }
493  
494 # Central Header Record/Zip64 extended field
495  
496 411 substr($ctl, 16, length $crc32) = $crc32 ;
497  
498 411 my $zip64Payload = '';
499  
500 # uncompressed length - only set zip64 if needed
501 411 ▶ if (*$self->{UnCompSize}->isAlmost64bit()) { # || *$self->{ZipData}{Zip64}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'UnCompSize'}->isAlmost64bit) { } 0 411 411
502 0 $zip64Payload .= *$self->{UnCompSize}->getPacked_V64() ;
503 } else {
504 411 substr($ctl, 24, 4) = *$self->{UnCompSize}->getPacked_V32() ;
505 }
506  
507 # compressed length - only set zip64 if needed
508 411 ▶ if (*$self->{CompSize}->isAlmost64bit()) { # || *$self->{ZipData}{Zip64}) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'CompSize'}->isAlmost64bit) { } 0 411 411
509 0 $zip64Payload .= *$self->{CompSize}->getPacked_V64() ;
510 } else {
511 411 substr($ctl, 20, 4) = *$self->{CompSize}->getPacked_V32() ;
512 }
513  
514 # Local Header offset
515 $zip64Payload .= *$self->{ZipData}{LocalHdrOffset}->getPacked_V64()
516 411 ▶ if *$self->{ZipData}{LocalHdrOffset}->is64bit() ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"ZipData"}{"LocalHdrOffset"}->is64bit 0 411 411
517  
518 # disk no - always zero, so don't need to include it.
519 #$zip64Payload .= pack "V", 0 ;
520  
521 411 my $zip64Xtra = '';
522  
523 411 ▶ if (length $zip64Payload) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $zip64Payload) 0 411 411
524 0 $zip64Xtra = IO::Compress::Zlib::Extra::mkSubField(ZIP_EXTRA_ID_ZIP64, $zip64Payload);
525  
526 substr($ctl, *$self->{ZipData}{ExtraOffset}, 2) =
527 0 pack 'v', *$self->{ZipData}{ExtraSize} + length $zip64Xtra;
528  
529 0 *$self->{ZipData}{AnyZip64} = 1;
530 }
531  
532 # Zip64 needs to be first in extra field to workaround a Windows Explorer Bug
533 # See http://www.info-zip.org/phpBB3/viewtopic.php?f=3&t=440 for details
534 411 $ctl .= $zip64Xtra . $ctlExtra . $comment;
535  
536 411 *$self->{ZipData}{Offset}->add32(length($hdr));
537 411 *$self->{ZipData}{Offset}->add( *$self->{CompSize} );
538 411 push @{ *$self->{ZipData}{CentralDir} }, $ctl ;
539  
540 411 return $hdr;
541 }
542  
543 sub mkFinalTrailer
544 345 ▶{
Subroutine mkFinalTrailer: called CC=7 SCAR=19.5
Pod undocumented
545 345 my $self = shift ;
546  
547 345 my $comment = '';
548 345 $comment = *$self->{ZipData}{ZipComment} ;
549  
550 345 my $cd_offset = *$self->{ZipData}{Offset}->get32bit() ; # offset to start central dir
551  
552 345 my $entries = @{ *$self->{ZipData}{CentralDir} };
553  
554 *$self->{ZipData}{AnyZip64} = 1
555 345 ▶ if *$self->{ZipData}{Offset}->is64bit || $entries >= 0xFFFF ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"ZipData"}{"Offset"}->is64bit or $entries >= 65535 0 345 345
Condition33%1/3
*$self->{"ZipData"}{"Offset"}->is64bit or $entries >= 65535
l!l&&r!l&&!r
00345
MC/DC0%0/2
*$self->{"ZipData"}{"Offset"}->is64bit or $entries >= 65535
*$self->{"ZipData"}{"Offset"}->is64bit $entries >= 65535
Truth table33%1/3
A or B
A= *$self->{"ZipData"}{"Offset"}->is64bitB= $entries >= 65535
ABresult
1X1
011
000
556  
557 345 my $cd = join '', @{ *$self->{ZipData}{CentralDir} };
558 345 my $cd_len = length $cd ;
559  
560 345 my $z64e = '';
561  
562 345 ▶ if ( *$self->{ZipData}{AnyZip64} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{"ZipData"}{"AnyZip64"}) 21 324 345
563  
564 21 my $v = *$self->{ZipData}{Version} ;
565 21 my $mb = *$self->{ZipData}{MadeBy} ;
566 21 $z64e .= pack 'v', $mb ; # Version made by
567 21 $z64e .= pack 'v', $v ; # Version to extract
568 21 $z64e .= pack 'V', 0 ; # number of disk
569 21 $z64e .= pack 'V', 0 ; # number of disk with central dir
570 21 $z64e .= U64::pack_V64 $entries ; # entries in central dir on this disk
571 21 $z64e .= U64::pack_V64 $entries ; # entries in central dir
572 21 $z64e .= U64::pack_V64 $cd_len ; # size of central dir
573 21 $z64e .= *$self->{ZipData}{Offset}->getPacked_V64() ; # offset to start central dir
574 $z64e .= *$self->{ZipData}{extrafieldzip64} # optional extra field
575 21 ▶ if defined *$self->{ZipData}{extrafieldzip64} ;
Branch: 1 branch
BranchTrueFalseTotal
if defined *$self->{"ZipData"}{"extrafieldzip64"} 0 21 21
576  
577 21 $z64e = pack("V", ZIP64_END_CENTRAL_REC_HDR_SIG) # signature
578 . U64::pack_V64(length $z64e)
579 . $z64e ;
580  
581 21 *$self->{ZipData}{Offset}->add32(length $cd) ;
582  
583 21 $z64e .= pack "V", ZIP64_END_CENTRAL_LOC_HDR_SIG; # signature
584 21 $z64e .= pack 'V', 0 ; # number of disk with central dir
585 21 $z64e .= *$self->{ZipData}{Offset}->getPacked_V64() ; # offset to end zip64 central dir
586 21 $z64e .= pack 'V', 1 ; # Total number of disks
587  
588 21 $cd_offset = IO::Compress::Base::Common::MAX32 ;
589 21 ▶ $cd_len = IO::Compress::Base::Common::MAX32 if IO::Compress::Base::Common::isGeMax32 $cd_len ;
Branch: 1 branch
BranchTrueFalseTotal
if IO::Compress::Base::Common::isGeMax32($cd_len) 0 21 21
590 21 ▶ $entries = 0xFFFF if $entries >= 0xFFFF ;
Branch: 1 branch
BranchTrueFalseTotal
if $entries >= 65535 0 21 21
591 }
592  
593 345 my $ecd = '';
594 345 $ecd .= pack "V", ZIP_END_CENTRAL_HDR_SIG ; # signature
595 345 $ecd .= pack 'v', 0 ; # number of disk
596 345 $ecd .= pack 'v', 0 ; # number of disk with central dir
597 345 $ecd .= pack 'v', $entries ; # entries in central dir on this disk
598 345 $ecd .= pack 'v', $entries ; # entries in central dir
599 345 $ecd .= pack 'V', $cd_len ; # size of central dir
600 345 $ecd .= pack 'V', $cd_offset ; # offset to start central dir
601 345 $ecd .= pack 'v', length $comment ; # zipfile comment length
602 345 $ecd .= $comment;
603  
604 345 return $cd . $z64e . $ecd ;
605 }
606  
607 sub ckParams
608 414 ▶{
Subroutine ckParams: called CC=26 SCAR=47.5
Pod undocumented
609 414 my $self = shift ;
610 414 my $got = shift;
611  
612 414 $got->setValue('crc32' => 1);
613  
614 414 ▶ if (! $got->parsed('time') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($got->parsed("time")) 325 89 414
615 # Modification time defaults to now.
616 325 $got->setValue('time' => time) ;
617 }
618  
619 414 ▶ if ($got->parsed('extime') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got->parsed("extime")) 0 414 414
620 0 my $timeRef = $got->getValue('extime');
621 0 ▶ if ( defined $timeRef) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $timeRef) 0 0 0
622 0 ▶ return $self->saveErrorString(undef, "exTime not a 3-element array ref")
Branch: 1 branch
BranchTrueFalseTotal
if ref $timeRef ne "ARRAY" or @$timeRef != 3 0 0 0
Condition0%0/3
ref $timeRef ne "ARRAY" or @$timeRef != 3
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $timeRef ne "ARRAY" or @$timeRef != 3
ref $timeRef ne "ARRAY" @$timeRef != 3
Truth table0%0/3
A or B
A= ref $timeRef ne "ARRAY"B= @$timeRef != 3
ABresult
1X1
011
000
623 if ref $timeRef ne 'ARRAY' || @$timeRef != 3;
624 }
625  
626 0 $got->setValue("mtime", $timeRef->[1]);
627 0 $got->setValue("atime", $timeRef->[0]);
628 0 $got->setValue("ctime", $timeRef->[2]);
629 }
630  
631 # Unix2/3 Extended Attribute
632 414 for my $name (qw(exunix2 exunixn))
633 {
634 828 ▶ if ($got->parsed($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got->parsed($name)) 0 828 828
635 0 my $idRef = $got->getValue($name);
636 0 ▶ if ( defined $idRef) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $idRef) 0 0 0
637 0 ▶ return $self->saveErrorString(undef, "$name not a 2-element array ref")
Branch: 1 branch
BranchTrueFalseTotal
if ref $idRef ne "ARRAY" or @$idRef != 2 0 0 0
Condition0%0/3
ref $idRef ne "ARRAY" or @$idRef != 2
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $idRef ne "ARRAY" or @$idRef != 2
ref $idRef ne "ARRAY" @$idRef != 2
Truth table0%0/3
A or B
A= ref $idRef ne "ARRAY"B= @$idRef != 2
ABresult
1X1
011
000
638 if ref $idRef ne 'ARRAY' || @$idRef != 2;
639 }
640  
641 0 $got->setValue("uid", $idRef->[0]);
642 0 $got->setValue("gid", $idRef->[1]);
643 0 $got->setValue("want_$name", $idRef);
644 }
645 }
646  
647 414 ▶ *$self->{ZipData}{AnyZip64} = 1
Branch: 1 branch
BranchTrueFalseTotal
if $got->getValue("zip64") or $got->getValue("extrafieldzip64") 26 388 414
Condition66%2/3
$got->getValue("zip64") or $got->getValue("extrafieldzip64")
l!l&&r!l&&!r
260388
MC/DC50%1/2
$got->getValue("zip64") or $got->getValue("extrafieldzip64")
$got->getValue("zip64") $got->getValue("extrafieldzip64")
Truth table66%2/3
A or B
A= $got->getValue("zip64")B= $got->getValue("extrafieldzip64")
ABresult
1X1
011
000
648 if $got->getValue('zip64') || $got->getValue('extrafieldzip64') ;
649 414 *$self->{ZipData}{Zip64} = $got->getValue('zip64');
650 414 *$self->{ZipData}{Stream} = $got->getValue('stream');
651  
652 414 my $method = $got->getValue('method');
653 return $self->saveErrorString(undef, "Unknown Method '$method'")
654 414 ▶ if ! defined $ZIP_CM_MIN_VERSIONS{$method};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $IO::Compress::Zip::ZIP_CM_MIN_VERSIONS{$method} 0 414 414
655  
656 414 ▶ return $self->saveErrorString(undef, "Bzip2 not available")
Branch: 1 branch
BranchTrueFalseTotal
if $method == 12 and not defined $IO::Compress::Adapter::Bzip2::VERSION 0 414 414
Condition66%2/3
$method == 12 and not defined $IO::Compress::Adapter::Bzip2::VERSION
!ll&&!rl&&r
393210
MC/DC0%0/2
$method == 12 and not defined $IO::Compress::Adapter::Bzip2::VERSION
$method == 12 not defined $IO::Compress::Adapter::Bzip2::VERSION
Truth table66%2/3
A and not(B)
A= $method == 12B= not defined $IO::Compress::Adapter::Bzip2::VERSION
ABresult
0X0
100
111
657 if $method == ZIP_CM_BZIP2 and
658 ! defined $IO::Compress::Adapter::Bzip2::VERSION;
659  
660 414 ▶ return $self->saveErrorString(undef, "Lzma not available")
Branch: 1 branch
BranchTrueFalseTotal
if $method == 14 and not defined $IO::Compress::Adapter::Lzma::VERSION 0 414 414
Condition33%1/3
$method == 14 and not defined $IO::Compress::Adapter::Lzma::VERSION
!ll&&!rl&&r
41400
MC/DC0%0/2
$method == 14 and not defined $IO::Compress::Adapter::Lzma::VERSION
$method == 14 not defined $IO::Compress::Adapter::Lzma::VERSION
Truth table33%1/3
A and not(B)
A= $method == 14B= not defined $IO::Compress::Adapter::Lzma::VERSION
ABresult
0X0
100
111
661 if $method == ZIP_CM_LZMA
662 and ! defined $IO::Compress::Adapter::Lzma::VERSION;
663  
664 414 *$self->{ZipData}{Method} = $method;
665  
666 414 *$self->{ZipData}{ZipComment} = $got->getValue('zipcomment') ;
667  
668 414 for my $name (qw( extrafieldlocal extrafieldcentral extrafieldzip64))
669 {
670 1242 my $data = $got->getValue($name) ;
671 1242 ▶ if (defined $data) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data) 0 1242 1242
672 0 my $bad = IO::Compress::Zlib::Extra::parseExtraField($data, 1, 0) ;
673 0 ▶ return $self->saveErrorString(undef, "Error with $name Parameter: $bad")
Branch: 1 branch
BranchTrueFalseTotal
if $bad 0 0 0
674 if $bad ;
675  
676 0 $got->setValue($name, $data) ;
677 0 *$self->{ZipData}{$name} = $data;
678 }
679 }
680  
681 return undef
682 414 ▶ if defined $IO::Compress::Bzip2::VERSION
Branch: 1 branch
BranchTrueFalseTotal
if defined $IO::Compress::Bzip2::VERSION and not IO::Compress::Bzip2::ckParams($self, $got) 0 414 414
Condition33%1/3
defined $IO::Compress::Bzip2::VERSION and not IO::Compress::Bzip2::ckParams($self, $got)
!ll&&!rl&&r
04140
MC/DC0%0/2
defined $IO::Compress::Bzip2::VERSION and not IO::Compress::Bzip2::ckParams($self, $got)
defined $IO::Compress::Bzip2::VERSION not IO::Compress::Bzip2::ckParams($self, $got)
Truth table33%1/3
A and not(B)
A= defined $IO::Compress::Bzip2::VERSIONB= not IO::Compress::Bzip2::ckParams($self, $got)
ABresult
0X0
100
111
683 and ! IO::Compress::Bzip2::ckParams($self, $got);
684  
685 414 ▶ if ($got->parsed('sparse') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got->parsed("sparse")) 0 414 414
686 0 *$self->{ZipData}{Sparse} = $got->getValue('sparse') ;
687 0 *$self->{ZipData}{Method} = ZIP_CM_STORE;
688 }
689  
690 414 ▶ if ($got->parsed('filtername')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got->parsed("filtername")) 3 411 414
691 3 my $v = $got->getValue('filtername') ;
692 3 ▶ *$self->{ZipData}{FilterName} = $v
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "CODE" 3 0 3
693 if ref $v eq 'CODE' ;
694 }
695  
696 414 return 1 ;
697 }
698  
699 sub outputPayload
700 399 ▶{
Subroutine outputPayload: called CC=2 SCAR=7.1
Pod undocumented
701 399 my $self = shift ;
702 399 ▶ return 1 if *$self->{ZipData}{Sparse} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"ZipData"}{"Sparse"} 0 399 399
703 399 return $self->output(@_);
704 }
705  
706  
707 #sub newHeader
708 #{
709 # my $self = shift ;
710 #
711 # return $self->mkHeader(*$self->{Got});
712 #}
713  
714  
715 47 ▶our %PARAMS = (
Branch: 2 branches
BranchTrueFalseTotal
$Compress::Raw::Zlib::gzip_os_code == 3 ? : 47 0 47
defined $IO::Compress::Bzip2::VERSION ? : 47 0 47
716 'stream' => [IO::Compress::Base::Common::Parse_boolean, 1],
717 #'store' => [IO::Compress::Base::Common::Parse_boolean, 0],
718 'method' => [IO::Compress::Base::Common::Parse_unsigned, ZIP_CM_DEFLATE],
719  
720 # # Zip header fields
721 'minimal' => [IO::Compress::Base::Common::Parse_boolean, 0],
722 'zip64' => [IO::Compress::Base::Common::Parse_boolean, 0],
723 'comment' => [IO::Compress::Base::Common::Parse_any, ''],
724 'zipcomment'=> [IO::Compress::Base::Common::Parse_any, ''],
725 'name' => [IO::Compress::Base::Common::Parse_any, ''],
726 'filtername'=> [IO::Compress::Base::Common::Parse_code, undef],
727 'canonicalname'=> [IO::Compress::Base::Common::Parse_boolean, 0],
728 'efs' => [IO::Compress::Base::Common::Parse_boolean, 0],
729 'time' => [IO::Compress::Base::Common::Parse_any, undef],
730 'extime' => [IO::Compress::Base::Common::Parse_any, undef],
731 'exunix2' => [IO::Compress::Base::Common::Parse_any, undef],
732 'exunixn' => [IO::Compress::Base::Common::Parse_any, undef],
733 'extattr' => [IO::Compress::Base::Common::Parse_any,
734 $Compress::Raw::Zlib::gzip_os_code == 3
735 ? 0100644 << 16
736 : 0],
737 'os_code' => [IO::Compress::Base::Common::Parse_unsigned, $Compress::Raw::Zlib::gzip_os_code],
738  
739 'textflag' => [IO::Compress::Base::Common::Parse_boolean, 0],
740 'extrafieldlocal' => [IO::Compress::Base::Common::Parse_any, undef],
741 'extrafieldcentral'=> [IO::Compress::Base::Common::Parse_any, undef],
742 'extrafieldzip64' => [IO::Compress::Base::Common::Parse_any, undef],
743  
744 # Lzma
745 'preset' => [IO::Compress::Base::Common::Parse_unsigned, 6],
746 'extreme' => [IO::Compress::Base::Common::Parse_boolean, 0],
747  
748 # For internal use only
749 'sparse' => [IO::Compress::Base::Common::Parse_unsigned, 0],
750  
751 IO::Compress::RawDeflate::getZlibParams(),
752 defined $IO::Compress::Bzip2::VERSION
753 ? IO::Compress::Bzip2::getExtraParams()
754 : ()
755  
756  
757 );
758  
759 sub getExtraParams
760 414 ▶{
Subroutine getExtraParams: called CC=1 SCAR=0.0
Pod undocumented
761 414 return %PARAMS ;
762 }
763  
764 sub getInverseClass
765 0 ▶{
Subroutine getInverseClass: not called CC=1 SCAR=0.2
Pod undocumented
766 47 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
767 0 return ('IO::Uncompress::Unzip',
768 \$IO::Uncompress::Unzip::UnzipError);
769 }
770  
771 sub getFileInfo
772 163 ▶{
Subroutine getFileInfo: called CC=12 SCAR=25.1
Pod undocumented
773 163 my $self = shift ;
774 163 my $params = shift;
775 163 my $filename = shift ;
776  
777 163 ▶ if (IO::Compress::Base::Common::isaScalar($filename))
Branch: 1 branch
BranchTrueFalseTotal
if (IO::Compress::Base::Common::isaScalar($filename)) 50 113 163
778 {
779 $params->setValue(zip64 => 1)
780 50 ▶ if IO::Compress::Base::Common::isGeMax32 length (${ $filename }) ;
Branch: 1 branch
BranchTrueFalseTotal
if IO::Compress::Base::Common::isGeMax32(length ${$filename;}) 0 50 50
781  
782 50 return ;
783 }
784  
785 113 my ($mode, $uid, $gid, $size, $atime, $mtime, $ctime) ;
786 113 ▶ if ( $params->parsed('storelinks') )
Branch: 1 branch
BranchTrueFalseTotal
if ($params->parsed('storelinks')) { } 0 113 113
787 {
788 0 ($mode, $uid, $gid, $size, $atime, $mtime, $ctime)
789 = (lstat($filename))[2, 4,5,7, 8,9,10] ;
790 }
791 else
792 {
793 113 ($mode, $uid, $gid, $size, $atime, $mtime, $ctime)
794 = (stat($filename))[2, 4,5,7, 8,9,10] ;
795 }
796  
797 113 ▶ $params->setValue(textflag => -T $filename )
Branch: 1 branch
BranchTrueFalseTotal
unless $params->parsed("textflag") 108 5 113
798 if ! $params->parsed('textflag');
799  
800 113 ▶ $params->setValue(zip64 => 1)
Branch: 1 branch
BranchTrueFalseTotal
if IO::Compress::Base::Common::isGeMax32($size) 0 113 113
801 if IO::Compress::Base::Common::isGeMax32 $size ;
802  
803 113 ▶ $params->setValue('name' => $filename)
Branch: 1 branch
BranchTrueFalseTotal
unless $params->parsed("name") 102 11 113
804 if ! $params->parsed('name') ;
805  
806 113 ▶ $params->setValue('time' => $mtime)
Branch: 1 branch
BranchTrueFalseTotal
unless $params->parsed("time") 106 7 113
807 if ! $params->parsed('time') ;
808  
809 113 ▶ if ( ! $params->parsed('extime'))
Branch: 1 branch
BranchTrueFalseTotal
unless ($params->parsed("extime")) 113 0 113
810 {
811 113 $params->setValue('mtime' => $mtime) ;
812 113 $params->setValue('atime' => $atime) ;
813 113 $params->setValue('ctime' => undef) ; # No Creation time
814 # TODO - see if can fill out creation time on non-Unix
815 }
816  
817 # NOTE - Unix specific code alert
818 113 ▶ if (! $params->parsed('extattr'))
Branch: 1 branch
BranchTrueFalseTotal
unless ($params->parsed("extattr")) 108 5 113
819 {
820 47 ▶ use Fcntl qw(:mode) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
821 108 my $attr = $mode << 16;
822 108 ▶ $attr |= ZIP_A_RONLY if ($mode & S_IWRITE) == 0 ;
Branch: 1 branch
BranchTrueFalseTotal
if ($mode & 128) == 0 0 108 108
823 108 ▶ $attr |= ZIP_A_DIR if ($mode & S_IFMT ) == S_IFDIR ;
Branch: 1 branch
BranchTrueFalseTotal
if ($mode & S_IFMT()) == 16384 0 108 108
824  
825 108 $params->setValue('extattr' => $attr);
826 }
827  
828 113 $params->setValue('want_exunixn', [$uid, $gid]);
829 113 $params->setValue('uid' => $uid) ;
830 113 $params->setValue('gid' => $gid) ;
831  
832 }
833  
834 sub mkExtendedTime
835 226 ▶{
Subroutine mkExtendedTime: called CC=3 SCAR=11.0
Pod undocumented
836 # order expected is m, a, c
837  
838 226 my $times = '';
839 226 my $bit = 1 ;
840 226 my $flags = 0;
841  
842 226 for my $time (@_)
843 {
844 452 ▶ if (defined $time)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $time) 339 113 452
845 {
846 339 $flags |= $bit;
847 339 $times .= pack("V", $time);
848 }
849  
850 452 $bit <<= 1 ;
851 }
852  
853 226 return IO::Compress::Zlib::Extra::mkSubField(ZIP_EXTRA_ID_EXT_TIMESTAMP,
854 pack("C", $flags) . $times);
855 }
856  
857 sub mkUnix2Extra
858 0 ▶{
Subroutine mkUnix2Extra: not called CC=2 SCAR=17.9
Pod undocumented
859 0 my $ids = '';
860 0 for my $id (@_)
861 {
862 0 $ids .= pack("v", $id);
863 }
864  
865 0 return IO::Compress::Zlib::Extra::mkSubField(ZIP_EXTRA_ID_INFO_ZIP_UNIX2,
866 $ids);
867 }
868  
869 sub mkUnixNExtra
870 113 ▶{
Subroutine mkUnixNExtra: called CC=1 SCAR=0.0
Pod undocumented
871 113 my $uid = shift;
872 113 my $gid = shift;
873  
874 # Assumes UID/GID are 32-bit
875 113 my $ids ;
876 113 $ids .= pack "C", 1; # version
877 113 $ids .= pack "C", $Config{uidsize};
878 113 $ids .= pack "V", $uid;
879 113 $ids .= pack "C", $Config{gidsize};
880 113 $ids .= pack "V", $gid;
881  
882 113 return IO::Compress::Zlib::Extra::mkSubField(ZIP_EXTRA_ID_INFO_ZIP_UNIXN,
883 $ids);
884 }
885  
886  
887 # from Archive::Zip
888 sub _unixToDosTime # Archive::Zip::Member
889 411 ▶{
Subroutine _unixToDosTime: called CC=1 SCAR=0.0
890 411 my $time_t = shift;
891  
892 # TODO - add something to cope with unix time < 1980
893 411 my ( $sec, $min, $hour, $mday, $mon, $year ) = localtime($time_t);
894 411 my $dt = 0;
895 411 $dt += ( $sec >> 1 );
896 411 $dt += ( $min << 5 );
897 411 $dt += ( $hour << 11 );
898 411 $dt += ( $mday << 16 );
899 411 $dt += ( ( $mon + 1 ) << 21 );
900 411 $dt += ( ( $year - 80 ) << 25 );
901 411 return $dt;
902 }
903  
904 47 1;
905  
906 __END__
« blib/lib/IO/Uncompress/Unzip.pm ↑ Summary blib/lib/IO/Uncompress/Gunzip.pm »