Skip to content

Commit 2db5b8d

Browse files
committed
Update Archive-Tar to CPAN version 2.36
[DELTA] 2.36 02/02/2020 - Add xz test files to MANIFEST 2.34 01/02/2020 (HEANEY && SKAJI) - Add xz support - Use 4 digit year in Time::Local call
1 parent ac3afc4 commit 2db5b8d

File tree

6 files changed

+86
-23
lines changed

6 files changed

+86
-23
lines changed

Porting/Maintainers.pl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,12 @@ package Maintainers;
123123
%Modules = (
124124

125125
'Archive::Tar' => {
126-
'DISTRIBUTION' => 'BINGOS/Archive-Tar-2.32.tar.gz',
126+
'DISTRIBUTION' => 'BINGOS/Archive-Tar-2.36.tar.gz',
127127
'FILES' => q[cpan/Archive-Tar],
128128
'BUGS' => 'bug-archive-tar@rt.cpan.org',
129129
'EXCLUDED' => [
130130
qw(t/07_ptardiff.t),
131+
qr{t/src/(long|short)/foo.txz},
131132
],
132133
},
133134

cpan/Archive-Tar/lib/Archive/Tar.pm

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ use vars qw[$DEBUG $error $VERSION $WARN $FOLLOW_SYMLINK $CHOWN $CHMOD
2727
];
2828

2929
@ISA = qw[Exporter];
30-
@EXPORT = qw[ COMPRESS_GZIP COMPRESS_BZIP ];
30+
@EXPORT = qw[ COMPRESS_GZIP COMPRESS_BZIP COMPRESS_XZ ];
3131
$DEBUG = 0;
3232
$WARN = 1;
3333
$FOLLOW_SYMLINK = 0;
34-
$VERSION = "2.32";
34+
$VERSION = "2.36";
3535
$CHOWN = 1;
3636
$CHMOD = 1;
3737
$SAME_PERMISSIONS = $> == 0 ? 1 : 0;
@@ -76,6 +76,7 @@ Archive::Tar - module for manipulations of tar archives
7676
$tar->write('files.tar'); # plain tar
7777
$tar->write('files.tgz', COMPRESS_GZIP); # gzip compressed
7878
$tar->write('files.tbz', COMPRESS_BZIP); # bzip2 compressed
79+
$tar->write('files.txz', COMPRESS_XZ); # xz compressed
7980
8081
=head1 DESCRIPTION
8182
@@ -147,12 +148,13 @@ backwards compatibility. Archive::Tar now looks at the file
147148
magic to determine what class should be used to open the file
148149
and will transparently Do The Right Thing.
149150
150-
Archive::Tar will warn if you try to pass a bzip2 compressed file and the
151-
IO::Zlib / IO::Uncompress::Bunzip2 modules are not available and simply return.
151+
Archive::Tar will warn if you try to pass a bzip2 / xz compressed file and the
152+
IO::Uncompress::Bunzip2 / IO::Uncompress::UnXz are not available and simply return.
152153
153154
Note that you can currently B<not> pass a C<gzip> compressed
154155
filehandle, which is not opened with C<IO::Zlib>, a C<bzip2> compressed
155-
filehandle, which is not opened with C<IO::Uncompress::Bunzip2>, nor a string
156+
filehandle, which is not opened with C<IO::Uncompress::Bunzip2>, a C<xz> compressed
157+
filehandle, which is not opened with C<IO::Uncompress::UnXz>, nor a string
156158
containing the full archive information (either compressed or
157159
uncompressed). These are worth while features, but not currently
158160
implemented. See the C<TODO> section.
@@ -246,16 +248,40 @@ sub _get_handle {
246248
return;
247249
};
248250

249-
### read the first 4 bites of the file to figure out which class to
251+
### read the first 6 bytes of the file to figure out which class to
250252
### use to open the file.
251-
sysread( $tmp, $magic, 4 );
253+
sysread( $tmp, $magic, 6 );
252254
close $tmp;
253255
}
254256

257+
### is it xz?
258+
### if you asked specifically for xz compression, or if we're in
259+
### read mode and the magic numbers add up, use xz
260+
if( XZ and (
261+
($compress eq COMPRESS_XZ) or
262+
( MODE_READ->($mode) and $magic =~ XZ_MAGIC_NUM )
263+
)
264+
) {
265+
if( MODE_READ->($mode) ) {
266+
$fh = IO::Uncompress::UnXz->new( $file ) or do {
267+
$self->_error( qq[Could not read '$file': ] .
268+
$IO::Uncompress::UnXz::UnXzError
269+
);
270+
return;
271+
};
272+
} else {
273+
$fh = IO::Compress::Xz->new( $file ) or do {
274+
$self->_error( qq[Could not write to '$file': ] .
275+
$IO::Compress::Xz::XzError
276+
);
277+
return;
278+
};
279+
}
280+
255281
### is it bzip?
256282
### if you asked specifically for bzip compression, or if we're in
257283
### read mode and the magic numbers add up, use bzip
258-
if( BZIP and (
284+
} elsif( BZIP and (
259285
($compress eq COMPRESS_BZIP) or
260286
( MODE_READ->($mode) and $magic =~ BZIP_MAGIC_NUM )
261287
)
@@ -1246,8 +1272,8 @@ Write the in-memory archive to disk. The first argument can either
12461272
be the name of a file or a reference to an already open filehandle (a
12471273
GLOB reference).
12481274
1249-
The second argument is used to indicate compression. You can either
1250-
compress using C<gzip> or C<bzip2>. If you pass a digit, it's assumed
1275+
The second argument is used to indicate compression. You can
1276+
compress using C<gzip>, C<bzip2> or C<xz>. If you pass a digit, it's assumed
12511277
to be the C<gzip> compression level (between 1 and 9), but the use of
12521278
constants is preferred:
12531279
@@ -1257,10 +1283,13 @@ constants is preferred:
12571283
# write a bzip compressed file
12581284
$tar->write( 'out.tbz', COMPRESS_BZIP );
12591285
1286+
# write a xz compressed file
1287+
$tar->write( 'out.txz', COMPRESS_XZ );
1288+
12601289
Note that when you pass in a filehandle, the compression argument
12611290
is ignored, as all files are printed verbatim to your filehandle.
12621291
If you wish to enable compression with filehandles, use an
1263-
C<IO::Zlib> or C<IO::Compress::Bzip2> filehandle instead.
1292+
C<IO::Zlib>, C<IO::Compress::Bzip2> or C<IO::Compress::Xz> filehandle instead.
12641293
12651294
The third argument is an optional prefix. All files will be tucked
12661295
away in the directory you specify as prefix. So if you have files
@@ -1696,8 +1725,8 @@ Creates a tar file from the list of files provided. The first
16961725
argument can either be the name of the tar file to create or a
16971726
reference to an open file handle (e.g. a GLOB reference).
16981727
1699-
The second argument is used to indicate compression. You can either
1700-
compress using C<gzip> or C<bzip2>. If you pass a digit, it's assumed
1728+
The second argument is used to indicate compression. You can
1729+
compress using C<gzip>, C<bzip2> or C<xz>. If you pass a digit, it's assumed
17011730
to be the C<gzip> compression level (between 1 and 9), but the use of
17021731
constants is preferred:
17031732
@@ -1707,10 +1736,13 @@ constants is preferred:
17071736
# write a bzip compressed file
17081737
Archive::Tar->create_archive( 'out.tbz', COMPRESS_BZIP, @filelist );
17091738
1739+
# write a xz compressed file
1740+
Archive::Tar->create_archive( 'out.txz', COMPRESS_XZ, @filelist );
1741+
17101742
Note that when you pass in a filehandle, the compression argument
17111743
is ignored, as all files are printed verbatim to your filehandle.
17121744
If you wish to enable compression with filehandles, use an
1713-
C<IO::Zlib> or C<IO::Compress::Bzip2> filehandle instead.
1745+
C<IO::Zlib>, C<IO::Compress::Bzip2> or C<IO::Compress::Xz> filehandle instead.
17141746
17151747
The remaining arguments list the files to be included in the tar file.
17161748
These files must all exist. Any files which don't exist or can't be
@@ -1915,11 +1947,19 @@ Returns true if C<Archive::Tar> can extract C<bzip2> compressed archives
19151947

19161948
sub has_bzip2_support { return BZIP }
19171949

1950+
=head2 $bool = Archive::Tar->has_xz_support
1951+
1952+
Returns true if C<Archive::Tar> can extract C<xz> compressed archives
1953+
1954+
=cut
1955+
1956+
sub has_xz_support { return XZ }
1957+
19181958
=head2 Archive::Tar->can_handle_compressed_files
19191959
19201960
A simple checking routine, which will return true if C<Archive::Tar>
1921-
is able to uncompress compressed archives on the fly with C<IO::Zlib>
1922-
and C<IO::Compress::Bzip2> or false if not both are installed.
1961+
is able to uncompress compressed archives on the fly with C<IO::Zlib>,
1962+
C<IO::Compress::Bzip2> and C<IO::Compress::Xz> or false if not both are installed.
19231963
19241964
You can use this as a shortcut to determine whether C<Archive::Tar>
19251965
will do what you think before passing compressed archives to its

cpan/Archive-Tar/lib/Archive/Tar/Constant.pm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package Archive::Tar::Constant;
33
BEGIN {
44
require Exporter;
55

6-
$VERSION = '2.32';
6+
$VERSION = '2.36';
77
@ISA = qw[Exporter];
88

99
require Time::Local if $^O eq "MacOS";
@@ -32,6 +32,7 @@ use constant BLOCK => 512;
3232

3333
use constant COMPRESS_GZIP => 9;
3434
use constant COMPRESS_BZIP => 'bzip2';
35+
use constant COMPRESS_XZ => 'xz';
3536

3637
use constant BLOCK_SIZE => sub { my $n = int($_[0]/BLOCK); $n++ if $_[0] % BLOCK; $n * BLOCK };
3738
use constant TAR_PAD => sub { my $x = shift || return; return "\0" x (BLOCK - ($x % BLOCK) ) };
@@ -58,7 +59,7 @@ use constant PACK => 'a100 a8 a8 a8 a12 a12 A8 a1 a100 a6 a2 a32 a32 a
5859
use constant NAME_LENGTH => 100;
5960
use constant PREFIX_LENGTH => 155;
6061

61-
use constant TIME_OFFSET => ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,70) : 0;
62+
use constant TIME_OFFSET => ($^O eq "MacOS") ? Time::Local::timelocal(0,0,0,1,0,1970) : 0;
6263
use constant MAGIC => "ustar";
6364
use constant TAR_VERSION => "00";
6465
use constant LONGLINK_NAME => '././@LongLink';
@@ -77,8 +78,16 @@ use constant BZIP => do { !$ENV{'PERL5_AT_NO_BZIP'} and
7778
$ENV{'PERL5_AT_NO_BZIP'} || $@ ? 0 : 1
7879
};
7980

81+
### allow XZ to be turned off using ENV: DEBUG only
82+
use constant XZ => do { !$ENV{'PERL5_AT_NO_XZ'} and
83+
eval { require IO::Compress::Xz;
84+
require IO::Uncompress::UnXz; };
85+
$ENV{'PERL5_AT_NO_XZ'} || $@ ? 0 : 1
86+
};
87+
8088
use constant GZIP_MAGIC_NUM => qr/^(?:\037\213|\037\235)/;
8189
use constant BZIP_MAGIC_NUM => qr/^BZh\d/;
90+
use constant XZ_MAGIC_NUM => qr/^\xFD\x37\x7A\x58\x5A\x00/;
8291

8392
use constant CAN_CHOWN => sub { ($> == 0 and $^O ne "MacOS" and $^O ne "MSWin32") };
8493
use constant CAN_READLINK => ($^O ne 'MSWin32' and $^O !~ /RISC(?:[ _])?OS/i and $^O ne 'VMS');

cpan/Archive-Tar/lib/Archive/Tar/File.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use Archive::Tar::Constant;
1313

1414
use vars qw[@ISA $VERSION];
1515
#@ISA = qw[Archive::Tar];
16-
$VERSION = '2.32';
16+
$VERSION = '2.36';
1717

1818
### set value to 1 to oct() it during the unpack ###
1919

cpan/Archive-Tar/t/02_methods.t

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,11 @@ my $TARX = $Class->new;
9999
my $TAR_FILE = File::Spec->catfile( @ROOT, 'bar.tar' );
100100
my $TGZ_FILE = File::Spec->catfile( @ROOT, 'foo.tgz' );
101101
my $TBZ_FILE = File::Spec->catfile( @ROOT, 'foo.tbz' );
102+
my $TXZ_FILE = File::Spec->catfile( @ROOT, 'foo.txz' );
102103
my $OUT_TAR_FILE = File::Spec->catfile( @ROOT, 'out.tar' );
103104
my $OUT_TGZ_FILE = File::Spec->catfile( @ROOT, 'out.tgz' );
104105
my $OUT_TBZ_FILE = File::Spec->catfile( @ROOT, 'out.tbz' );
106+
my $OUT_TXZ_FILE = File::Spec->catfile( @ROOT, 'out.txz' );
105107

106108
my $COMPRESS_FILE = 'copy';
107109
$^O eq 'VMS' and $COMPRESS_FILE .= '.';
@@ -110,8 +112,8 @@ chmod 0644, $COMPRESS_FILE;
110112

111113
### done setting up environment ###
112114

113-
### check for zlib/bzip2 support
114-
{ for my $meth ( qw[has_zlib_support has_bzip2_support] ) {
115+
### check for zlib/bzip2/xz support
116+
{ for my $meth ( qw[has_zlib_support has_bzip2_support has_xz_support] ) {
115117
can_ok( $Class, $meth );
116118
}
117119
}
@@ -167,6 +169,7 @@ chmod 0644, $COMPRESS_FILE;
167169
{ my @to_try = ($TAR_FILE);
168170
push @to_try, $TGZ_FILE if $Class->has_zlib_support;
169171
push @to_try, $TBZ_FILE if $Class->has_bzip2_support;
172+
push @to_try, $TXZ_FILE if $Class->has_xz_support;
170173

171174
for my $type( @to_try ) {
172175

@@ -462,6 +465,7 @@ SKIP: { ### pesky warnings
462465
{ my @out;
463466
push @out, [ $OUT_TGZ_FILE => 1 ] if $Class->has_zlib_support;
464467
push @out, [ $OUT_TBZ_FILE => COMPRESS_BZIP ] if $Class->has_bzip2_support;
468+
push @out, [ $OUT_TXZ_FILE => COMPRESS_XZ ] if $Class->has_xz_support;
465469

466470
for my $entry ( @out ) {
467471

@@ -786,8 +790,14 @@ sub slurp_compressed_file {
786790
my $file = shift;
787791
my $fh;
788792

793+
### xz
794+
if( $file =~ /.txz$/ ) {
795+
require IO::Uncompress::UnXz;
796+
$fh = IO::Uncompress::UnXz->new( $file )
797+
or warn( "Error opening '$file' with IO::Uncompress::UnXz" ), return
798+
789799
### bzip2
790-
if( $file =~ /.tbz$/ ) {
800+
} elsif( $file =~ /.tbz$/ ) {
791801
require IO::Uncompress::Bunzip2;
792802
$fh = IO::Uncompress::Bunzip2->new( $file )
793803
or warn( "Error opening '$file' with IO::Uncompress::Bunzip2" ), return

cpan/Archive-Tar/t/09_roundtrip.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ push @file_only_archives, [qw( src short foo.tgz )]
4343
if Archive::Tar->has_zlib_support;
4444
push @file_only_archives, [qw( src short foo.tbz )]
4545
if Archive::Tar->has_bzip2_support;
46+
push @file_only_archives, [qw( src short foo.txz )]
47+
if Archive::Tar->has_xz_support;
4648

4749
@file_only_archives = map File::Spec->catfile(@$_), @file_only_archives;
4850

@@ -74,6 +76,7 @@ for my $archive_name (@file_only_archives) {
7476
my @compress =
7577
$ext =~ /t?gz$/ ? (COMPRESS_GZIP)
7678
: $ext =~ /(tbz|bz2?)$/ ? (COMPRESS_BZIP)
79+
: $ext =~ /(t?xz)$/ ? (COMPRESS_XZ)
7780
: ();
7881

7982
my ( $fh, $filename ) = tempfile( UNLINK => 1 );

0 commit comments

Comments
 (0)