"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/Archive/Tar.pm" between
Archive-Tar-2.32.tar.gz and Archive-Tar-2.34.tar.gz

About: Archive-Tar is a Perl module for creation and in-memory manipulation of tar files.

Tar.pm  (Archive-Tar-2.32):Tar.pm  (Archive-Tar-2.34)
skipping to change at line 30 skipping to change at line 30
require Exporter; require Exporter;
use strict; use strict;
use vars qw[$DEBUG $error $VERSION $WARN $FOLLOW_SYMLINK $CHOWN $CHMOD use vars qw[$DEBUG $error $VERSION $WARN $FOLLOW_SYMLINK $CHOWN $CHMOD
$DO_NOT_USE_PREFIX $HAS_PERLIO $HAS_IO_STRING $SAME_PERMISSIONS $DO_NOT_USE_PREFIX $HAS_PERLIO $HAS_IO_STRING $SAME_PERMISSIONS
$INSECURE_EXTRACT_MODE $ZERO_PAD_NUMBERS @ISA @EXPORT $RESOLVE_SYMLI NK $INSECURE_EXTRACT_MODE $ZERO_PAD_NUMBERS @ISA @EXPORT $RESOLVE_SYMLI NK
]; ];
@ISA = qw[Exporter]; @ISA = qw[Exporter];
@EXPORT = qw[ COMPRESS_GZIP COMPRESS_BZIP ]; @EXPORT = qw[ COMPRESS_GZIP COMPRESS_BZIP COMPRESS_XZ ];
$DEBUG = 0; $DEBUG = 0;
$WARN = 1; $WARN = 1;
$FOLLOW_SYMLINK = 0; $FOLLOW_SYMLINK = 0;
$VERSION = "2.32"; $VERSION = "2.34";
$CHOWN = 1; $CHOWN = 1;
$CHMOD = 1; $CHMOD = 1;
$SAME_PERMISSIONS = $> == 0 ? 1 : 0; $SAME_PERMISSIONS = $> == 0 ? 1 : 0;
$DO_NOT_USE_PREFIX = 0; $DO_NOT_USE_PREFIX = 0;
$INSECURE_EXTRACT_MODE = 0; $INSECURE_EXTRACT_MODE = 0;
$ZERO_PAD_NUMBERS = 0; $ZERO_PAD_NUMBERS = 0;
$RESOLVE_SYMLINK = $ENV{'PERL5_AT_RESOLVE_SYMLINK'} || 'speed'; $RESOLVE_SYMLINK = $ENV{'PERL5_AT_RESOLVE_SYMLINK'} || 'speed';
BEGIN { BEGIN {
use Config; use Config;
skipping to change at line 79 skipping to change at line 79
$tar->add_data('file/baz.txt', 'This is the contents now'); $tar->add_data('file/baz.txt', 'This is the contents now');
$tar->rename('oldname', 'new/file/name'); $tar->rename('oldname', 'new/file/name');
$tar->chown('/', 'root'); $tar->chown('/', 'root');
$tar->chown('/', 'root:root'); $tar->chown('/', 'root:root');
$tar->chmod('/tmp', '1777'); $tar->chmod('/tmp', '1777');
$tar->write('files.tar'); # plain tar $tar->write('files.tar'); # plain tar
$tar->write('files.tgz', COMPRESS_GZIP); # gzip compressed $tar->write('files.tgz', COMPRESS_GZIP); # gzip compressed
$tar->write('files.tbz', COMPRESS_BZIP); # bzip2 compressed $tar->write('files.tbz', COMPRESS_BZIP); # bzip2 compressed
$tar->write('files.txz', COMPRESS_XZ); # xz compressed
=head1 DESCRIPTION =head1 DESCRIPTION
Archive::Tar provides an object oriented mechanism for handling tar Archive::Tar provides an object oriented mechanism for handling tar
files. It provides class methods for quick and easy files handling files. It provides class methods for quick and easy files handling
while also allowing for the creation of tar file objects for custom while also allowing for the creation of tar file objects for custom
manipulation. If you have the IO::Zlib module installed, manipulation. If you have the IO::Zlib module installed,
Archive::Tar will also support compressed or gzipped tar files. Archive::Tar will also support compressed or gzipped tar files.
An object of class Archive::Tar represents a .tar(.gz) archive full An object of class Archive::Tar represents a .tar(.gz) archive full
skipping to change at line 150 skipping to change at line 151
The first argument can either be the name of a file or a reference to The first argument can either be the name of a file or a reference to
an already open filehandle (or an IO::Zlib object if it's compressed) an already open filehandle (or an IO::Zlib object if it's compressed)
The C<read> will I<replace> any previous content in C<$tar>! The C<read> will I<replace> any previous content in C<$tar>!
The second argument may be considered optional, but remains for The second argument may be considered optional, but remains for
backwards compatibility. Archive::Tar now looks at the file backwards compatibility. Archive::Tar now looks at the file
magic to determine what class should be used to open the file magic to determine what class should be used to open the file
and will transparently Do The Right Thing. and will transparently Do The Right Thing.
Archive::Tar will warn if you try to pass a bzip2 compressed file and the Archive::Tar will warn if you try to pass a bzip2 / xz compressed file and the
IO::Zlib / IO::Uncompress::Bunzip2 modules are not available and simply return. IO::Uncompress::Bunzip2 / IO::Uncompress::UnXz are not available and simply retu
rn.
Note that you can currently B<not> pass a C<gzip> compressed Note that you can currently B<not> pass a C<gzip> compressed
filehandle, which is not opened with C<IO::Zlib>, a C<bzip2> compressed filehandle, which is not opened with C<IO::Zlib>, a C<bzip2> compressed
filehandle, which is not opened with C<IO::Uncompress::Bunzip2>, nor a string filehandle, which is not opened with C<IO::Uncompress::Bunzip2>, a C<xz> compres
sed
filehandle, which is not opened with C<IO::Uncompress::UnXz>, nor a string
containing the full archive information (either compressed or containing the full archive information (either compressed or
uncompressed). These are worth while features, but not currently uncompressed). These are worth while features, but not currently
implemented. See the C<TODO> section. implemented. See the C<TODO> section.
The third argument can be a hash reference with options. Note that The third argument can be a hash reference with options. Note that
all options are case-sensitive. all options are case-sensitive.
=over 4 =over 4
=item limit =item limit
skipping to change at line 249 skipping to change at line 251
my $fh; my $fh;
{ ### reading magic only makes sense if we're opening a file for { ### reading magic only makes sense if we're opening a file for
### reading. otherwise, just use what the user requested. ### reading. otherwise, just use what the user requested.
my $magic = ''; my $magic = '';
if( MODE_READ->($mode) ) { if( MODE_READ->($mode) ) {
open my $tmp, $file or do { open my $tmp, $file or do {
$self->_error( qq[Could not open '$file' for reading: $!] ); $self->_error( qq[Could not open '$file' for reading: $!] );
return; return;
}; };
### read the first 4 bites of the file to figure out which class to ### read the first 6 bytes of the file to figure out which class to
### use to open the file. ### use to open the file.
sysread( $tmp, $magic, 4 ); sysread( $tmp, $magic, 6 );
close $tmp; close $tmp;
} }
### is it xz?
### if you asked specifically for xz compression, or if we're in
### read mode and the magic numbers add up, use xz
if( XZ and (
($compress eq COMPRESS_XZ) or
( MODE_READ->($mode) and $magic =~ XZ_MAGIC_NUM )
)
) {
if( MODE_READ->($mode) ) {
$fh = IO::Uncompress::UnXz->new( $file ) or do {
$self->_error( qq[Could not read '$file': ] .
$IO::Uncompress::UnXz::UnXzError
);
return;
};
} else {
$fh = IO::Compress::Xz->new( $file ) or do {
$self->_error( qq[Could not write to '$file': ] .
$IO::Compress::Xz::XzError
);
return;
};
}
### is it bzip? ### is it bzip?
### if you asked specifically for bzip compression, or if we're in ### if you asked specifically for bzip compression, or if we're in
### read mode and the magic numbers add up, use bzip ### read mode and the magic numbers add up, use bzip
if( BZIP and ( } elsif( BZIP and (
($compress eq COMPRESS_BZIP) or ($compress eq COMPRESS_BZIP) or
( MODE_READ->($mode) and $magic =~ BZIP_MAGIC_NUM ) ( MODE_READ->($mode) and $magic =~ BZIP_MAGIC_NUM )
) )
) { ) {
### different reader/writer modules, different error vars... sigh ### different reader/writer modules, different error vars... sigh
if( MODE_READ->($mode) ) { if( MODE_READ->($mode) ) {
$fh = IO::Uncompress::Bunzip2->new( $file, MultiStream => 1 ) or do { $fh = IO::Uncompress::Bunzip2->new( $file, MultiStream => 1 ) or do {
$self->_error( qq[Could not read '$file': ] . $self->_error( qq[Could not read '$file': ] .
$IO::Uncompress::Bunzip2::Bunzip2Error $IO::Uncompress::Bunzip2::Bunzip2Error
skipping to change at line 1247 skipping to change at line 1273
return 1; return 1;
} }
=head2 $tar->write ( [$file, $compressed, $prefix] ) =head2 $tar->write ( [$file, $compressed, $prefix] )
Write the in-memory archive to disk. The first argument can either Write the in-memory archive to disk. The first argument can either
be the name of a file or a reference to an already open filehandle (a be the name of a file or a reference to an already open filehandle (a
GLOB reference). GLOB reference).
The second argument is used to indicate compression. You can either The second argument is used to indicate compression. You can
compress using C<gzip> or C<bzip2>. If you pass a digit, it's assumed compress using C<gzip>, C<bzip2> or C<xz>. If you pass a digit, it's assumed
to be the C<gzip> compression level (between 1 and 9), but the use of to be the C<gzip> compression level (between 1 and 9), but the use of
constants is preferred: constants is preferred:
# write a gzip compressed file # write a gzip compressed file
$tar->write( 'out.tgz', COMPRESS_GZIP ); $tar->write( 'out.tgz', COMPRESS_GZIP );
# write a bzip compressed file # write a bzip compressed file
$tar->write( 'out.tbz', COMPRESS_BZIP ); $tar->write( 'out.tbz', COMPRESS_BZIP );
# write a xz compressed file
$tar->write( 'out.txz', COMPRESS_XZ );
Note that when you pass in a filehandle, the compression argument Note that when you pass in a filehandle, the compression argument
is ignored, as all files are printed verbatim to your filehandle. is ignored, as all files are printed verbatim to your filehandle.
If you wish to enable compression with filehandles, use an If you wish to enable compression with filehandles, use an
C<IO::Zlib> or C<IO::Compress::Bzip2> filehandle instead. C<IO::Zlib>, C<IO::Compress::Bzip2> or C<IO::Compress::Xz> filehandle instead.
The third argument is an optional prefix. All files will be tucked The third argument is an optional prefix. All files will be tucked
away in the directory you specify as prefix. So if you have files away in the directory you specify as prefix. So if you have files
'a' and 'b' in your archive, and you specify 'foo' as prefix, they 'a' and 'b' in your archive, and you specify 'foo' as prefix, they
will be written to the archive as 'foo/a' and 'foo/b'. will be written to the archive as 'foo/a' and 'foo/b'.
If no arguments are given, C<write> returns the entire formatted If no arguments are given, C<write> returns the entire formatted
archive as a string, which could be useful if you'd like to stuff the archive as a string, which could be useful if you'd like to stuff the
archive into a socket or a pipe to gzip or something. archive into a socket or a pipe to gzip or something.
skipping to change at line 1695 skipping to change at line 1724
} }
=head1 Class Methods =head1 Class Methods
=head2 Archive::Tar->create_archive($file, $compressed, @filelist) =head2 Archive::Tar->create_archive($file, $compressed, @filelist)
Creates a tar file from the list of files provided. The first Creates a tar file from the list of files provided. The first
argument can either be the name of the tar file to create or a argument can either be the name of the tar file to create or a
reference to an open file handle (e.g. a GLOB reference). reference to an open file handle (e.g. a GLOB reference).
The second argument is used to indicate compression. You can either The second argument is used to indicate compression. You can
compress using C<gzip> or C<bzip2>. If you pass a digit, it's assumed compress using C<gzip>, C<bzip2> or C<xz>. If you pass a digit, it's assumed
to be the C<gzip> compression level (between 1 and 9), but the use of to be the C<gzip> compression level (between 1 and 9), but the use of
constants is preferred: constants is preferred:
# write a gzip compressed file # write a gzip compressed file
Archive::Tar->create_archive( 'out.tgz', COMPRESS_GZIP, @filelist ); Archive::Tar->create_archive( 'out.tgz', COMPRESS_GZIP, @filelist );
# write a bzip compressed file # write a bzip compressed file
Archive::Tar->create_archive( 'out.tbz', COMPRESS_BZIP, @filelist ); Archive::Tar->create_archive( 'out.tbz', COMPRESS_BZIP, @filelist );
# write a xz compressed file
Archive::Tar->create_archive( 'out.txz', COMPRESS_XZ, @filelist );
Note that when you pass in a filehandle, the compression argument Note that when you pass in a filehandle, the compression argument
is ignored, as all files are printed verbatim to your filehandle. is ignored, as all files are printed verbatim to your filehandle.
If you wish to enable compression with filehandles, use an If you wish to enable compression with filehandles, use an
C<IO::Zlib> or C<IO::Compress::Bzip2> filehandle instead. C<IO::Zlib>, C<IO::Compress::Bzip2> or C<IO::Compress::Xz> filehandle instead.
The remaining arguments list the files to be included in the tar file. The remaining arguments list the files to be included in the tar file.
These files must all exist. Any files which don't exist or can't be These files must all exist. Any files which don't exist or can't be
read are silently ignored. read are silently ignored.
If the archive creation fails for any reason, C<create_archive> will If the archive creation fails for any reason, C<create_archive> will
return false. Please use the C<error> method to find the cause of the return false. Please use the C<error> method to find the cause of the
failure. failure.
Note that this method does not write C<on the fly> as it were; it Note that this method does not write C<on the fly> as it were; it
skipping to change at line 1913 skipping to change at line 1945
sub has_zlib_support { return ZLIB } sub has_zlib_support { return ZLIB }
=head2 $bool = Archive::Tar->has_bzip2_support =head2 $bool = Archive::Tar->has_bzip2_support
Returns true if C<Archive::Tar> can extract C<bzip2> compressed archives Returns true if C<Archive::Tar> can extract C<bzip2> compressed archives
=cut =cut
sub has_bzip2_support { return BZIP } sub has_bzip2_support { return BZIP }
=head2 $bool = Archive::Tar->has_xz_support
Returns true if C<Archive::Tar> can extract C<xz> compressed archives
=cut
sub has_xz_support { return XZ }
=head2 Archive::Tar->can_handle_compressed_files =head2 Archive::Tar->can_handle_compressed_files
A simple checking routine, which will return true if C<Archive::Tar> A simple checking routine, which will return true if C<Archive::Tar>
is able to uncompress compressed archives on the fly with C<IO::Zlib> is able to uncompress compressed archives on the fly with C<IO::Zlib>,
and C<IO::Compress::Bzip2> or false if not both are installed. C<IO::Compress::Bzip2> and C<IO::Compress::Xz> or false if not both are installe
d.
You can use this as a shortcut to determine whether C<Archive::Tar> You can use this as a shortcut to determine whether C<Archive::Tar>
will do what you think before passing compressed archives to its will do what you think before passing compressed archives to its
C<read> method. C<read> method.
=cut =cut
sub can_handle_compressed_files { return ZLIB && BZIP ? 1 : 0 } sub can_handle_compressed_files { return ZLIB && BZIP ? 1 : 0 }
sub no_string_support { sub no_string_support {
 End of changes. 17 change blocks. 
16 lines changed or deleted 59 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)