Archive-Tar-Wrapper-0.41/0000755000175000017500000000000014631574755014146 5ustar alceualceuArchive-Tar-Wrapper-0.41/t/0000755000175000017500000000000014631574755014411 5ustar alceualceuArchive-Tar-Wrapper-0.41/t/010openbsd.t0000644000175000017500000000212114607331411016424 0ustar alceualceuuse warnings; use strict; use Test::More tests => 7; use Archive::Tar::Wrapper; use File::Spec; use File::Which qw(which); SKIP: { skip 'This test is designed to run only on OpenBSD', 7 unless ( $^O eq 'openbsd' ); my $tar_path = which('tar'); note("tar available at $tar_path"); my $tar = Archive::Tar::Wrapper->new( tar_read_options => 'p' ); is( $tar->{tar_read_options}, '-p', 'tar parameters on OpenBSD have a "-" prefix' ); ok( $tar->_is_openbsd(), 'correctly identify the OS' ); is_deeply( $tar->_read_openbsd_opts('z'), [ "$tar_path", '-z', '-x', '-p' ], 'got correct options for gziped tarball' ) or diag( explain( $tar->_read_openbsd_opts('z') ) ); is_deeply( $tar->_read_openbsd_opts('j'), [ "$tar_path", '-j', '-x', '-p' ], 'got correct options for bziped tarball' ) or diag( explain( $tar->_read_openbsd_opts('j') ) ); for my $file (qw(bar.tar foo.tgz foo.tar.bz2)) { ok( $tar->read( File::Spec->catfile( 't', 'data', $file ) ), "read tarball $file" ); } } Archive-Tar-Wrapper-0.41/t/003Dirs.t0000644000175000017500000000135714607331411015707 0ustar alceualceuuse warnings; use strict; use Log::Log4perl qw(:easy); use File::Path; use File::Temp qw(tempfile tempdir); my $TARDIR = "data"; $TARDIR = "t/$TARDIR" unless -d $TARDIR; my $TMPDIR = tempdir( CLEANUP => 1 ); use Test::More tests => 4; BEGIN { use_ok('Archive::Tar::Wrapper') } rmdir $TMPDIR if -d $TMPDIR; mkdir $TMPDIR or die "Cannot mkdir $TMPDIR"; END { rmtree $TMPDIR } my $arch = Archive::Tar::Wrapper->new( tmpdir => $TMPDIR, dirs => 1 ); ok( $arch->read("$TARDIR/bar.tar"), "opening compressed tarfile" ); my $e = $arch->list_all(); my $all = join " ", sort( map { $_->[0] } @$e ); is( $all, ". bar bar/bar.dat bar/foo.dat", "list all dirs" ); my @dirs = map { $_->[0] } grep { $_->[2] eq "d" } @$e; is( "@dirs", ". bar", "dirs only" ); Archive-Tar-Wrapper-0.41/t/data/0000755000175000017500000000000014631574755015322 5ustar alceualceuArchive-Tar-Wrapper-0.41/t/data/foo.tgz0000644000175000017500000000053014607331411016610 0ustar alceualceuZBj@ eb؆V*Rҥajss&HwEt-[$.91,zs6gl{=/1bh! b;җB9^Ur?IMKS)U!%tm$s9"ϥfj-qMr^ZHe {QFVT+3LUTيs{ ifnX]T^v2~D=fg4[Hmq<=;"[{hwîc~^9:޻nʭgufLƦz)tW_ (Archive-Tar-Wrapper-0.41/t/data/bar.tar0000644000175000017500000002400014607331411016551 0ustar alceualceubar/0040775000076400007640000000000010270764326012041 5ustar mschillimschillibar/bar.dat0100664000076400007640000000001310270764317013266 0ustar mschillimschillibarcontent bar/foo.dat0100664000076400007640000000001310270764326013305 0ustar mschillimschillifoocontent Archive-Tar-Wrapper-0.41/t/data/foo.tar.bz20000644000175000017500000000054414607331411017273 0ustar alceualceuBZh91AY&SY R.@\}v0:`m@M@A&j0z&4@QLh4Mx"󨀅 N0Ԓ 9T!;b>*2V1ndBo* 2tNf16c)F} {{J ͣI5`mS ƒ+% YbS\b,)򌱽8g5fAuIgwzY A'Dnew(); is( $arch->is_compressed( File::Spec->catdir( @dirs, 'foo.tgz' ) ), 'z', 'Identify a gziped tarball' ); is( $arch->is_compressed( File::Spec->catdir( @dirs, 'foo.tar.bz2' ) ), 'j', 'Identify a bziped tarball' ); is( $arch->is_compressed( File::Spec->catdir( @dirs, 'bar.tar' ) ), '', 'Identify non-compressed tarball' ); ok( !$arch->is_compressed( File::Spec->catdir( @dirs, 'bar.tar' ) ), 'Non-compressed tarball evaluate as false' ); my $temp_dir = tempdir( CLEANUP => 1 ); my $gziped_undercover = File::Spec->catdir( $temp_dir, 'foo' ); copy( File::Spec->catdir( @dirs, 'foo.tgz' ), $gziped_undercover ); is( $arch->is_compressed($gziped_undercover), 'z', 'Detects gziped file without file extension' ); done_testing; Archive-Tar-Wrapper-0.41/t/001Basic.t0000644000175000017500000001353114631574714016036 0ustar alceualceuuse warnings; use strict; use Log::Log4perl qw(:easy); use FindBin qw($Bin); use File::Temp qw(tempfile); use Test::More tests => 24; use File::Spec; use Config; use constant TARDIR => 't/data'; Log::Log4perl->easy_init($ERROR); BEGIN { use_ok('Archive::Tar::Wrapper') } umask(0); my $arch = Archive::Tar::Wrapper->new(); diag( 'Is GNU tar? ' . ( $arch->is_gnu ? 'yes' : 'no' ) ); diag( 'Is BSD tar? ' . ( $arch->is_bsd ? 'yes' : 'no' ) ); diag( 'Version information: ' . $arch->{version_info} ); diag( 'tar error: ' . $arch->{tar_error_msg} ) if ( ( defined( $arch->{tar_error_msg} ) ) and ( $arch->{tar_error_msg} ne '' ) ); ok( $arch->read( File::Spec->catfile( TARDIR, 'foo.tgz' ) ), 'can open the compressed tar file' ); ok( $arch->locate('001Basic.t'), 'find 001Basic.t inside the compressed tar file' ); ok( $arch->locate('./001Basic.t'), 'find ./001Basic.t inside the compressed tar file' ); ok( !$arch->locate('nonexist'), 'cannot find non-existing file inside the compressed tar file' ); note('Add a new file'); my $tmploc = $arch->locate('001Basic.t'); ok( $arch->add( 'foo/bar/baz', $tmploc ), 'adding file' ); note('Add data'); my $data = 'this is data'; ok( $arch->add( 'foo/bar/string', \$data ), 'adding data' ); ok( $arch->locate('foo/bar/baz'), 'find added file' ); ok( $arch->add( 'foo/bar/permtest', $tmploc, { perm => oct(770) } ), 'adding file' ); note('Make a tarball'); my ( $fh, $filename ) = tempfile( UNLINK => 1 ); ok( $arch->write($filename), 'Tarring up' ); my $a2 = Archive::Tar::Wrapper->new(); ok( $a2->read($filename), 'Reading in new tarball' ); my @got = sort( map { $_->[0] } @{ $a2->list_all } ); is_deeply( \@got, [qw(001Basic.t foo/bar/baz foo/bar/permtest foo/bar/string)], 'list_all() returns the expected list elements' ); my $f1 = $a2->locate('001Basic.t'); my $f2 = $a2->locate('foo/bar/baz'); ok( -s $f1 > 0, 'Checking tarball files sizes' ); ok( -s $f2 > 0, 'Checking tarball files sizes' ); is( -s $f1, -s $f2, 'Comparing tarball files sizes' ); my $f3 = $a2->locate('foo/bar/permtest'); my $expected_permission = sprintf '%3o', ( ( stat($f3) )[2] & 07777 ); SKIP: { skip 'Permissions are too different on Microsoft Windows', 1 if ( $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys' ); is( $expected_permission, '770', 'testing file permission inside the tarball' ); } my $f4 = $a2->locate('foo/bar/string'); open( my $in, '<', $f4 ) or die "Cannot open $f4: $!"; my $got_data = join '', <$in>; close($in); is( $got_data, $data, 'comparing file data' ); note('Iterators'); # required to be invoke since list_all() invokes it implicit $arch->list_reset(); my @elements; while ( my $entry = $arch->list_next() ) { push @elements, $entry->[0]; } @elements = sort(@elements); is_deeply( \@elements, [qw(001Basic.t foo/bar/baz foo/bar/permtest foo/bar/string)], 'list_next() produce the expected results' ); note('Check optional file names for extraction'); my $a3 = Archive::Tar::Wrapper->new(); $a3->read( File::Spec->catfile( TARDIR, 'bar.tar' ), 'bar/bar.dat' ); my $elements = $a3->list_all(); is( scalar(@$elements), 1, 'only one file extracted' ); is( $elements->[0]->[0], 'bar/bar.dat', 'the first index of list_all() has the expected data' ); note('Ask for non-existent files in tarball'); my $a4 = Archive::Tar::Wrapper->new(); # Suppress the warning Log::Log4perl->get_logger('')->level($FATAL); SKIP: { skip( 'FreeBSD\'s tar is too lenient - skipping', 1 ) if ( $^O =~ /freebsd/i ); skip 'bsdtar is too lenient', 1 if ( $a4->is_bsd() ); my $rc = $a4->read( File::Spec->catfile( TARDIR, 'bar.tar' ), 'bar/bar.dat', 'quack/schmack' ); is( $rc, undef, 'Failure to ask for non-existent files' ); } note('Testing original file permissions'); umask(022); my $a5 = Archive::Tar::Wrapper->new( tar_read_options => 'p', ); $a5->read( File::Spec->catfile( TARDIR, 'bar.tar' ) ); $f1 = $a5->locate('bar/bar.dat'); # TODO: add conditional note on Alpine to indicate that tar over there is broken regarding -p parameter if ($f1) { $expected_permission = sprintf '%3o', ( ( stat($f1) )[2] & 07777 ); } else { note( 'Could not locate "bar/bar.dat" inside the tarball ' . File::Spec->catfile( TARDIR, 'bar.tar' ) ); } SKIP: { skip 'Cannot check permissions on a non-existent file', 1 unless $f1; skip 'Permissions are too different on Microsoft Windows', 1 if ( $Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys' ); is( $expected_permission, '664', 'testing file permissions' ) or diag( 'Known bug in Alpine Linux: https://bugs.busybox.net/show_bug.cgi?id=16102' ); } SKIP: { # gnu options my $a6 = Archive::Tar::Wrapper->new( tar_gnu_read_options => ['--numeric-owner'], ); my $is_gnu = $a6->is_gnu(); note( $a6->{tar_error_msg} ) if ( defined( $a6->{tar_error_msg} ) ); skip 'Only with gnu tar', 1 unless $is_gnu; $a6->read( File::Spec->catfile( TARDIR, 'bar.tar' ) ); $f1 = $a6->locate('bar/bar.dat'); ok( defined $f1, 'numeric owner works' ); } note('Trying to test GNU options'); SKIP: { # gnu options my $tar = Archive::Tar::Wrapper->new( tar_gnu_write_options => ['--exclude=foo'], ); my $is_gnu = $tar->is_gnu(); note( $tar->{tar_error_msg} ) if ( defined( $tar->{tar_error_msg} ) ); skip 'Test is possible only with GNU tar', 1 unless $is_gnu; my $file_loc = $tar->locate('001Basic.t'); $tar->add( 'foo/bar/baz', $0 ); $tar->add( 'boo/bar/baz', $0 ); my ( $fh, $filename ) = tempfile( UNLINK => 1, SUFFIX => '.tgz' ); $tar->write( $filename, 1 ); my $tar_read = Archive::Tar::Wrapper->new(); $tar_read->read($filename); for my $entry ( @{ $tar_read->list_all() } ) { my ( $tar_path, $real_path ) = @$entry; is( $tar_path, 'boo/bar/baz', 'foo excluded' ); } } Archive-Tar-Wrapper-0.41/t/004Utf8.t0000644000175000017500000000207014607331411015626 0ustar alceualceuuse warnings; use strict; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($ERROR); use File::Temp qw(tempfile); my $TARDIR = "data"; $TARDIR = "t/$TARDIR" unless -d $TARDIR; use Test::More tests => 6; BEGIN { use_ok('Archive::Tar::Wrapper') } SKIP: { if ( $] < 5.008 ) { skip "Unicode tests skipped with perl < 5.8", 5; } umask(0); my $arch = Archive::Tar::Wrapper->new(); ok( $arch->read("$TARDIR/foo.tgz"), "opening compressed tarfile" ); # Add data my $data = "this is data \x{00fc}"; ok( $arch->add( "foo/bar/string", \$data, { binmode => ":utf8" } ), "adding data" ); # Make a tarball my ( $fh, $filename ) = tempfile( UNLINK => 1 ); ok( $arch->write($filename), "Tarring up" ); # List my $a2 = Archive::Tar::Wrapper->new(); ok( $a2->read($filename), "Reading in new tarball" ); my $f1 = $a2->locate("foo/bar/string"); open FILE, "<:utf8", $f1 or die "Cannot open $f1"; my $got_data = join '', ; close FILE; is( $got_data, $data, "comparing file utf8 data" ); } Archive-Tar-Wrapper-0.41/t/012tarinfo.t0000644000175000017500000000355114607331411016446 0ustar alceualceuuse warnings; use strict; use Test::More tests => 14; use Archive::Tar::Wrapper; use File::Which; note('Testing generic interface, should work everywhere'); my $arch = Archive::Tar::Wrapper->new(); # don't use those methods yourself outside these tests! $arch->_acquire_tar_info(); ok( $arch->{version_info}, 'has version_info' ); is( $arch->{tar_exit_code}, 0, 'has the expected exit code' ); ok( defined( $arch->is_gnu ), 'is_gnu is defined' ); ok( defined( $arch->is_bsd ), 'is_bsd is defined' ); note('Specific tests for OpenBSD'); SKIP: { skip 'Not running on OpenBSD', 3 unless ( $^O eq 'openbsd' ); $arch = Archive::Tar::Wrapper->new(); ok( !$arch->is_gnu, 'tar is not GNU' ); ok( $arch->is_bsd, 'tar is BSD' ); like( $arch->{version_info}, qr/^Information not available/, 'OpenBSD has no version information' ); } note('All tests below are forced to ignore platform specific details'); note('Faking error when executing tar'); my $tar; if ( $^O eq 'MSWin32' ) { $tar = which('bsdtar'); } else { $tar = which('tar'); } $arch = Archive::Tar::Wrapper->new( osname => 'yadayadayada', tar => $tar ); $arch->{tar_exit_code} = 42; $arch->_acquire_tar_info(1); like( $arch->{version_info}, qr/^Information not available/, 'on error has no version information' ); is( $arch->is_gnu, 0, 'is not GNU tar' ); is( $arch->is_bsd, 0, 'is not BSD tar' ); note('Testing as GNU tar'); $arch->{tar_exit_code} = 0; $arch->{version_info} = 'tar (GNU tar) 1.26'; $arch->_acquire_tar_info(1); ok( $arch->is_gnu, 'tar is GNU' ); ok( !$arch->is_bsd, 'tar is not BSD' ); note('Testing as BSD tar'); $arch->{tar_exit_code} = 1; $arch->{version_info} = 'bsdtar 2.4.12 - libarchive 2.4.12'; $arch->{tar} = '/usr/bin/bsdtar'; $arch->_acquire_tar_info(1); ok( !$arch->is_gnu, 'tar is not GNU' ); ok( $arch->is_bsd, 'tar is BSD' ); Archive-Tar-Wrapper-0.41/t/011remdots.t0000644000175000017500000000161314607331411016455 0ustar alceualceuuse strict; use warnings; use Archive::Tar::Wrapper; use Test::More; my $arch = Archive::Tar::Wrapper->new(); my @samples = ( [ '.', '..', 'ar', 'ogoyugfyu', 'iohoihoi', 'pojij' ], [ '..', 'buiv', 'oihoih', 'oiggf', '.' ], [ 'uiuig', 'ohphpui', 'nuvg', '.', '..' ], [ 'uigbyufcd', 'opkokj', '.', '..', 'ugoig' ], [ 'uigbyufcd', '.', 'opkokj', '..', 'ugoig' ] ); plan tests => scalar(@samples); for my $sample_ref (@samples) { $arch->_rem_dots($sample_ref); ok( has_no_dots($sample_ref), 'all dots removed' ) or diag( explain($sample_ref) ); } sub has_no_dots { my $entries_ref = shift; my $result = 1; for my $entry ( @{$entries_ref} ) { if ( ( $entry eq '.' ) or ( $entry eq '..' ) ) { $result = 0; last; } } return $result; } Archive-Tar-Wrapper-0.41/t/002Mult.t0000644000175000017500000000154014607331411015720 0ustar alceualceuuse warnings; use strict; use Log::Log4perl qw(:easy); use File::Path; use File::Temp qw(tempfile tempdir); my $TARDIR = "data"; $TARDIR = "t/$TARDIR" unless -d $TARDIR; my $TMPDIR = tempdir( CLEANUP => 1 ); use Test::More tests => 5; BEGIN { use_ok('Archive::Tar::Wrapper') } my $arch = Archive::Tar::Wrapper->new( tmpdir => $TMPDIR ); ok( $arch->read("$TARDIR/foo.tgz"), "opening compressed tarfile" ); ok( $arch->read("$TARDIR/bar.tar"), "opening uncompressed" ); my $elements = $arch->list_all(); my $got = join " ", sort map { $_->[0] } @$elements; is( $got, "001Basic.t bar/bar.dat bar/foo.dat", "file check" ); # Iterators $arch->list_reset(); my @elements = (); while ( my $entry = $arch->list_next() ) { push @elements, $entry->[0]; } $got = join " ", sort @elements; is( $got, "001Basic.t bar/bar.dat bar/foo.dat", "file check via iterator" ); Archive-Tar-Wrapper-0.41/t/006DirPerms.t0000644000175000017500000000216714607355261016547 0ustar alceualceuuse warnings; use strict; use Log::Log4perl qw(:easy); use Config; Log::Log4perl->easy_init($ERROR); use File::Temp qw(tempfile tempdir); my $TARDIR = "data"; $TARDIR = "t/$TARDIR" unless -d $TARDIR; use Test::More tests => 4; BEGIN { use_ok('Archive::Tar::Wrapper') } my $arch = Archive::Tar::Wrapper->new(); my $tempdir = tempdir( CLEANUP => 1 ); my ( $fh, $tarfile ) = tempfile( UNLINK => 1 ); # to get predictable results regardless of local umask settings umask 0002; my $foodir = "$tempdir/foo"; my $foofile = "$foodir/foofile"; mkdir "$foodir"; chmod 0710, $foodir; open(my $fh2, '>', $foofile) or die "Cannot open $foofile ($!)"; print $fh2 "blech\n"; close($fh2); ok( $arch->add( "foo/foofile", $foofile ), "adding file" ); # Make a tarball ok( $arch->write($tarfile), "Tarring up" ); SKIP: { skip 'Permissions are too different on Microsoft Windows', 1 if ($Config{osname} eq 'MSWin32' || $Config{osname} eq 'msys'); my $tarread = Archive::Tar::Wrapper->new(); $tarread->read($tarfile); my $loc = $tarread->locate("foo"); my $mode = ( stat $loc )[2] & 07777; is $mode, 0710, "check dir mode"; } Archive-Tar-Wrapper-0.41/t/007bzip.t0000644000175000017500000000172414607331411015754 0ustar alceualceuuse warnings; use strict; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($ERROR); use File::Which; use File::Temp qw(tempfile); use Test::More tests => 5; use File::Spec; BEGIN { use_ok('Archive::Tar::Wrapper') } my $bzip2_path = which('bzip2'); unless ( defined($bzip2_path) ) { diag( 'bzip2 is not available on your path! Beware that you will not be able to pack/unpack tarballs compressed with it, please install it ASAP!' ); } SKIP: { skip 'bzip2 program is not available', 4 unless ( defined($bzip2_path) ); my $TARDIR = 'data'; $TARDIR = File::Spec->catdir( 't', $TARDIR ) unless -d $TARDIR; umask(0); my $arch = Archive::Tar::Wrapper->new(); ok( $arch->read( File::Spec->catfile( $TARDIR, 'foo.tar.bz2' ) ), "opening compressed tarfile" ); ok( $arch->locate('001Basic.t'), "find 001Basic.t" ); ok( $arch->locate('./001Basic.t'), "find ./001Basic.t" ); ok( !$arch->locate('nonexist'), "find nonexist" ); } Archive-Tar-Wrapper-0.41/t/005Cwd.t0000644000175000017500000000106114607331411015515 0ustar alceualceuuse warnings; use strict; use File::Temp qw(tempfile); use Cwd; use Test::More tests => 4; BEGIN { use_ok('Archive::Tar::Wrapper') } my $cwd = getcwd(); my $evaled = eval { my $arch = Archive::Tar::Wrapper->new(); my ( undef, $filename ) = tempfile( UNLINK => 1 ); unlink $filename; # OPEN => 0 gave a stupid warning # attempt to generate error from tar by not adding any files $arch->write( $filename, 9 ); 1; }; is $@, '', 'no error'; is $evaled, 1, 'survived eval'; is getcwd(), $cwd, 'still in original directory'; Archive-Tar-Wrapper-0.41/README.md0000644000175000017500000001255414607354737015433 0ustar alceualceu![Unit tests](https://github.com/glasswalk3r/archive-tar-wrapper-perl/actions/workflows/unit-test.yml/badge.svg?branch=master) # NAME Archive::Tar::Wrapper - API wrapper around the 'tar' utility # SYNOPSIS ```perl use Archive::Tar::Wrapper; my $arch = Archive::Tar::Wrapper->new(); # Open a tarball, expand it into a temporary directory $arch->read("archive.tgz"); # Iterate over all entries in the archive $arch->list_reset(); # Reset Iterator # Iterate through archive while(my $entry = $arch->list_next()) { my($tar_path, $phys_path) = @$entry; print "$tar_path\n"; } # Get a huge list with all entries for my $entry (@{$arch->list_all()}) { my($tar_path, $real_path) = @$entry; print "Tarpath: $tar_path Tempfile: $real_path\n"; } # Add a new entry $arch->add($logic_path, $file_or_stringref); # Remove an entry $arch->remove($logic_path); # Find the physical location of a temporary file my($tmp_path) = $arch->locate($tar_path); # Create a tarball $arch->write($tarfile, $compress); ``` # DESCRIPTION `Archive::Tar::Wrapper` is an API wrapper around the `tar` command line program. It never stores anything in memory, but works on temporary directory structures on disk instead. It provides a mapping between the logical paths in the tarball and the 'real' files in the temporary directory on disk. It differs from `Archive::Tar` in two ways: * `Archive::Tar::Wrapper` doesn't hold anything in memory. Everything is stored on disk. * `Archive::Tar::Wrapper` is 100% compliant with the platform's `tar` utility, because it uses it internally. # DOCUMENTATION Be sure to check out the POD documentation available with the distribution! # KNOWN LIMITATIONS * Currently, only `tar` programs supporting the `z` option (for compressing/decompressing) are supported. Future version will use `gzip` alternatively. * Currently, you can't add empty directories to a tarball directly. You could add a temporary file within a directory, and then `remove()` the file. * If you delete a file, the empty directories it was located in stay in the tarball. You could try to `locate()` them and delete them. This will be fixed, though. * Filenames containing newlines are causing problems with the list iterators. To be fixed. * If you ask `Archive::Tar::Wrapper` to add a file to a tarball, it copies it into a temporary directory and then calls the system tar to wrap up that directory into a tarball. This approach has limitations when it comes to file permissions: If the file to be added belongs to a different user/group, `Archive::Tar::Wrapper` will adjust the uid/gid/permissions of the target file in the temporary directory to reflect the original file's settings, to make sure the system tar will add it like that to the tarball, just like a regular tar run on the original file would. But this will fail of course if the original file's uid is different from the current user's, unless the script is running with superuser rights. The tar program by itself (without `Archive::Tar::Wrapper`) works differently: It'll just make a note of a file's uid/gid/permissions in the tarball (which it can do without superuser rights) and upon extraction, it'll adjust the permissions of newly generated files if the -p option is given (default for superuser). # BUGS `Archive::Tar::Wrapper` doesn't currently handle filenames with embedded newlines. ## Microsoft Windows support Support on Microsoft Windows is limited. Version below Windows 10 will not be supported for desktops, and for servers from Windows 2012 and above. The GNU `tar.exe` program doesn't work properly with the current interface of `Archive::Tar::Wrapper`. You must use the `bsdtar.exe` and make sure it appears first in the `PATH` environment variable than the GNU tar (if it is installed). See [http://libarchive.org/](http://libarchive.org/) for details about how to download and install `bsdtar.exe`, or go to [http://gnuwin32.sourceforge.net/packages.html](http://gnuwin32.sourceforge.net/packages.html) for a direct download. Windows 10 might come already with bsdtar program installed. Check [https://blogs.technet.microsoft.com/virtualization/2017/12/19/tar-and-curl-come-to-windows/](https://blogs.technet.microsoft.com/virtualization/2017/12/19/tar-and-curl-come-to-windows/) for more details. Having spaces in the path string to the `tar` program might be an issue too. Although there is some effort in terms of workaround it, you best might avoid it completely by installing in a different path than `C:\Program Files`. # LEGALESE This software is copyright (c) 2005 of Mike Schilli. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Archive-Tar-Wrapper. If not, see [http://www.gnu.org/licenses/](http://www.gnu.org/licenses/). # AUTHOR 2005, Mike Schilli # MAINTAINER 2018, Alceu Rodrigues de Freitas Junior Archive-Tar-Wrapper-0.41/Changes0000644000175000017500000002044514607331411015425 0ustar alceualceu###################################################################### Revision history for Perl extension Archive::Tar::Wrapper 0.38 (2020/08/09): Fixed issue 17 - https://github.com/glasswalk3r/archive-tar-wrapper-perl/issues/17 The fixes were only related to different licenses over the files of the distribution. Small fixes over the documentation as well. No changes to the code. :-) 0.37 (2019/08/24): Fixed issue 14 - https://github.com/glasswalk3r/archive-tar-wrapper-perl/issues/14 0.36 (2019/04/11): Bug fixes since tests on Windows were failing after latests changes. Refactored code due unexpected way bsdtar on Windows and tar on OpenBSD behave. Refactored the tests due the bugs found. Small fixes on Pod, specially the section for MS Windows users. Added the missing tests to the MANIFEST. 0.35 (2019/04/05): Added _rem_dots method, a improved way to remove '.' and '..' from readdir(), supposed to be faster than previous implementation with sort() and shift(). Added two more tests to increase testing coverage. Fixed a small bug regarding Pod, that now covers 100% of the code. Small fixes to documentation. 0.34 (2019/03/22): Increased test coverage. Refactored code to make it easier for testing. Disabled performance-small.t for now. Refactored bzip2 tests. Adding META.yml "provides" from Makefile.PL Covered methods that didn't have Pod. Refactored all Pod following best practices. Refactored a single method to be "private". Slightly changed new() to enable unit testing for OS specific configurations. 0.33 (2018/07/10): Skipping bzip2 testing if the program is not available (https://github.com/glasswalk3r/archive-tar-wrapper-perl/issues/11). Undeclared dependency of Dumbbench (https://github.com/glasswalk3r/archive-tar-wrapper-perl/issues/12). 0.32 (2018/07/10): Typo fixed by Mohammad S Anwar (https://github.com/glasswalk3r/archive-tar-wrapper-perl/pull/10). Refactored performance tests, and now they will run as TODO to test the hypotesis that there is a better algorithm to write() method. 0.31 (2018/07/03): Enabled performance testing to acquire from different setups which scheme is faster to remove dots when reading directories. Disabled Solaris OS until issues are fixed. Fixed bug introduced in Makefile.PL due changes of release 0.30 (thanks to David Cantrell ). Updated documentation. 0.30 (2018/06): Keeping track of changes per request https://github.com/glasswalk3r/archive-tar-wrapper-perl/issues/7. Fixing proper handling of File::Which when checking on Microsoft Windows. Refactored troubleshooting messages on Microsoft Windows. Bug fixes provided by Shoichi Kaji (skaji at cpan.org) in PRs https://github.com/glasswalk3r/archive-tar-wrapper-perl/pull/9 and https://github.com/glasswalk3r/archive-tar-wrapper-perl/pull/8 0.29 (2018/06/25): Added Microsoft Windows support with the help of Ingram Braun M.A. . 0.28 (2018/06/19) Moving Test::Simple dependency to TEST_REQUIRES per issue https://github.com/glasswalk3r/archive-tar-wrapper-perl/issues/6. Removed the README (completely replaced by README.md). Fixed licensing declaration per https://github.com/glasswalk3r/archive-tar-wrapper-perl/issues/5. Refactored more debugging messages with proper use of Log::Log4perl. Applied the usage of Test::More is_deeply() whenever possible to improve tests results in case of errors. Small refactorings. 0.27 (2018/06/15) Added Test::Simple 1.302073 as minimum version required to be able to use is_deeply(). Getting a logger from Log::Log4perl to be able to improve performance by avoiding doing expensive string concatenation unless the log level allows it. Reverted changes on list_reset() to go back reading and printing each line recovered instead of keeping it in memory, instead of following PBP. Refactored t/001Basic.t by following PBP, using three arguments for open() and adding note() to include more information. 0.26 (2018/06/09) Implemented refactoring due warnings from Perl::Critic. 0.25 (2018/06/04) Implemented refactoring due warnings from Perl::Critic. Merge pull request #3 from manwar/suggest-code-tidy 0.24 (2018/06/02) Added a LICENSE file (GNU GPL v3). Removed MYMETA files (see https://rt.cpan.org/Ticket/Display.html?id=108171). Improved Kwalitee by adding information to Makefile.PL Fixed tests under OpenBSD Added some code to check for OpenBSD tar, which is not quite compatible to the command line options passed by this module. Also made the method is_gnu() more robust, testing the return code and properly handling STDOUT and STDERR when trying "tar --version". Dependencies added are those already available on standard perl (Config and IPC::Open3). Added a README.md for better formatting in Github project page. Small refactorings and code formating with perltidy. 0.23 (2015/05/28) (ms) Mark Gardner added separate skips in the test suite to deal with the absense of GNU tar: https://github.com/mschilli/archive-tar-wrapper-perl/pull/7 0.22 (2015/03/08) (ms) Added tar_gnu_write_options option suggested by Csaba Major with tests and docs. 0.21 (2014/10/16) (ms) [rt.cpan.org 87536] Setting default umask to get predictable test results regardless of local umask settings. 0.20 (2014/09/29) (ms) Ignore errors on chown/chgrp when files from different owners/groups are copied into a tarball, accept the limitation that they'll be owned by the script user unless we're running as superuser. 0.19 (2014/02/16) (ms) RsrchBoy added support for bzip2-compressed tarfiles. 0.18 (2013/07/15) (ms) Moved to tmpdir() in t/002Mult.t because some smoke testers don't like writing into t/data. 0.17 (2013/07/01) (ms) Sanko Robinson replaced bin_find() by File::Which::which() to allow for better Win32 portability. 0.16 (2012/03/19) (ms) [rt.cpan.org 75770] Allow add() with directories, and now preserves directory permissions. 0.15 (2011/12/20) (ms) [RT 73046] Randy Stauner submitted a patch to reset the directory if a write() fails (e.g. because no files have been added). https://github.com/mschilli/archive-tar-wrapper-perl/pull/1 0.14 (2011/02/12) (ms) Added 'ramdisk' feature for Linux (ms) More search paths for 'tar' 0.13 2010/02/01 (ms) Added GNU tar check is_gnu() (ms) Added tar_gnu_read_options to specify options like --numeric-owner 0.12 2008/07/03 (ms) Applied modified patch by Daniel Barthel to enable more files added to a tarball than there are allowed on the command line. 0.11 2008/03/09 (ms) Skipping one test case for FreeBSD's tar, which does not complain if asked to extract non-existent files. 0.10 2007/07/21 (ms) Skipping unicode tests for perl < 5.8 0.09 2007/07/20 (ms) Added utf8 support in add($dataref) (ms) Fixed bug in add($ref) for adding string data, patch submitted by Karthik Joshi. (ms) Changed tempfile CLEANUP to UNLINK in test suite 0.08 2006/08/21 (ms) Added tardir() method to obtain the directory the tarball was unpacked in. 0.07 2006/04/02 (ms) Fixed list_all() to return a ref to an array of arrayrefs, as explained in the docs. (ms) Added "dirs" option to list directories as well. 0.06 2005/09/22 (ms) Fixed logging message in tar->read(). (ms) Additional options can be passed to tar (tar_read/write_options) (ms) failed read() no longer chdirs out of the current directory (ms) Fixed test suite for different umasks 0.05 2005/09/10 (ms) 'tar' is now running via IPC::Run (ms) read() takes an optional list of files to save space in case only a limited number of files is needed from the tarball. 0.04 2005/07/24 (ms) Added eg/tarflat and more test cases 0.03 2005/05/23 (ms) tarup() no longer uses "." as a directory, but globs for all top-level entries (ms) critical fix for location of tarred files (ms) tmp dir cleanup now handled manually to avoid File::Temp warnings 0.02 2005/04/20 (ms) Added lots of documentation. 0.01 2005/04/10 (ms) Where it all began. Archive-Tar-Wrapper-0.41/lib/0000755000175000017500000000000014631574755014714 5ustar alceualceuArchive-Tar-Wrapper-0.41/lib/Archive/0000755000175000017500000000000014631574755016275 5ustar alceualceuArchive-Tar-Wrapper-0.41/lib/Archive/Tar/0000755000175000017500000000000014631574755017023 5ustar alceualceuArchive-Tar-Wrapper-0.41/lib/Archive/Tar/Wrapper.pm0000644000175000017500000010144614631574714021002 0ustar alceualceupackage Archive::Tar::Wrapper; use strict; use warnings; use File::Temp qw(tempdir); use Log::Log4perl qw(:easy); use File::Spec::Functions; use File::Spec; use File::Path; use File::Copy; use File::Find; use File::Basename; use File::Which qw(which); use IPC::Run qw(run); use Cwd; use Config; use IPC::Open3; use Symbol 'gensym'; use Carp; our $VERSION = '0.41'; my $logger = get_logger(); =pod =head1 NAME Archive::Tar::Wrapper - API wrapper around the 'tar' utility =head1 SYNOPSIS use Archive::Tar::Wrapper; my $arch = Archive::Tar::Wrapper->new(); # Open a tarball, expand it into a temporary directory $arch->read("archive.tgz"); # Iterate over all entries in the archive $arch->list_reset(); # Reset Iterator # Iterate through archive while(my $entry = $arch->list_next()) { my($tar_path, $phys_path) = @$entry; print "$tar_path\n"; } # Get a huge list with all entries for my $entry (@{$arch->list_all()}) { my($tar_path, $real_path) = @$entry; print "Tarpath: $tar_path Tempfile: $real_path\n"; } # Add a new entry $arch->add($logic_path, $file_or_stringref); # Remove an entry $arch->remove($logic_path); # Find the physical location of a temporary file my($tmp_path) = $arch->locate($tar_path); # Create a tarball $arch->write($tarfile, $compress); =head1 DESCRIPTION B is an API wrapper around the C command line program. It never stores anything in memory, but works on temporary directory structures on disk instead. It provides a mapping between the logical paths in the tarball and the 'real' files in the temporary directory on disk. It differs from L in two ways: =over 4 =item * B almost doesn't hold anything in memory (see C method), instead using disk as storage. =item * B is 100% compliant with the platform's C utility because it uses it internally. =back =head1 METHODS =head2 new my $arch = Archive::Tar::Wrapper->new(); Constructor for the C wrapper class. Finds the C executable by searching C and returning the first hit. In case you want to use a different tar executable, you can specify it as a parameter: my $arch = Archive::Tar::Wrapper->new(tar => '/path/to/tar'); Since B creates temporary directories to store C data, the location of the temporary directory can be specified: my $arch = Archive::Tar::Wrapper->new(tmpdir => '/path/to/tmpdir'); Tremendous performance increases can be achieved if the temporary directory is located on a RAM disk. Check the L section for details. Additional options can be passed to the C command by using the C and C parameters. Example: my $arch = Archive::Tar::Wrapper->new( tar_read_options => 'p' ); will use C to extract the tarball instead of just C. GNU tar supports even more options, these can be passed in via my $arch = Archive::Tar::Wrapper->new( tar_gnu_read_options => ["--numeric-owner"], ); Similarly, C can be used to provide additional options for GNU tar implementations. For example, the tar object my $tar = Archive::Tar::Wrapper->new( tar_gnu_write_options => ["--exclude=foo"], ); will call the C utility internally like tar cf tarfile --exclude=foo ... when the C method gets called. By default, the C functions will return only file entries: directories will be suppressed. To have C return directories as well, use my $arch = Archive::Tar::Wrapper->new( dirs => 1 ); If more files are added to a tarball than the command line can handle, B will switch from using the command tar cfv tarfile file1 file2 file3 ... to tar cfv tarfile -T filelist where C is a file containing all file to be added. The default for this switch is 512, but it can be changed by setting the parameter C: my $arch = Archive::Tar::Wrapper->new( max_cmd_line_args => 1024 ); The expectable parameters are: =over =item * tar =item * tmpdir =item * tar_read_options =item * tar_write_options =item * tar_gnu_read_options =item * tar_gnu_write_options =item * max_cmd_line_args: defaults to 512 =item * ramdisk =back Returns a new instance of the class. =cut sub new { my ( $class, %options ) = @_; my $self = { tar => delete $options{tar} || undef, tmpdir => undef, tar_read_options => '', tar_write_options => '', tar_error_msg => undef, tar_gnu_read_options => [], tar_gnu_write_options => [], dirs => 0, max_cmd_line_args => 512, ramdisk => undef, _os_names => { openbsd => 'openbsd', mswin => 'MSWin32', solaris => 'solaris' }, # hack used to enable unit testing osname => delete $options{osname} || $Config{osname}, bzip2_regex => qr/\.bz2$/ix, gzip_regex => qr/\.t? # an optional t for matching tgz gz$ # ending with gz, which means compressed by gzip /ix, tar_error_msg => undef, version_info => undef, tar_exit_code => undef, is_gnu => undef, is_bsd => undef, version_info => undef, tar_exit_code => undef, %options, }; bless $self, $class; unless ( defined $self->{tar} ) { if ( ( $self->_is_openbsd ) and ( $self->{tar_read_options} ) ) { $self->{tar_read_options} = '-' . $self->{tar_read_options}; } if ( $self->{osname} eq 'MSWin32' ) { $self->_setup_mswin(); } else { $self->{tar} = which('tar') || which('gtar'); } unless ( defined $self->{tar} ) { # this is specific for testing under MS Windows smokers without tar installed # "OS unsupported" will mark the testing as NA instead of failure as convention. if ( $self->{osname} eq 'MSWin32' ) { LOGDIE 'tar not found in PATH, OS unsupported'; } else { LOGDIE 'tar not found in PATH, please specify location'; } } } $self->_acquire_tar_info(); if ( defined $self->{ramdisk} ) { my $rc = $self->ramdisk_mount( %{ $self->{ramdisk} } ); unless ($rc) { LOGDIE "Mounting ramdisk failed"; } $self->{tmpdir} = $self->{ramdisk}->{tmpdir}; } else { $self->{tmpdir} = tempdir( $self->{tmpdir} ? ( DIR => $self->{tmpdir} ) : () ); } $self->{tardir} = File::Spec->catfile( $self->{tmpdir}, 'tar' ); mkpath [ $self->{tardir} ], 0, oct(755) or LOGDIE 'Cannot create the path ' . $self->{tardir} . ": $!"; $logger->debug( 'tardir location: ' . $self->{tardir} ) if ( $logger->is_debug ); $self->{objdir} = tempdir(); return $self; } =head2 read $arch->read("archive.tgz"); C opens the given tarball, expands it into a temporary directory and returns 1 on success or C on failure. The temporary directory holding the tar data gets cleaned up when C<$arch> goes out of scope. C handles both compressed and uncompressed files. To find out if a file is compressed or uncompressed, it tries to guess by extension, then by checking the first couple of bytes in the tarfile. If only a limited number of files is needed from a tarball, they can be specified after the tarball name: $arch->read("archive.tgz", "path/file.dat", "path/sub/another.txt"); The file names are passed unmodified to the C command, make sure that the file paths match exactly what's in the tarball, otherwise C will fail. =cut sub _is_openbsd { my $self = shift; return ( $self->{osname} eq $self->{_os_names}->{openbsd} ); } sub _is_solaris { my $self = shift; return ( $self->{osname} eq $self->{_os_names}->{solaris} ); } sub _read_solaris_opts { my ( $self, $compress_opt ) = @_; my @cmd; push( @cmd, $self->{tar} ); push( @cmd, 'xp' ); if ($compress_opt) { $cmd[-1] .= $compress_opt; } $cmd[-1] .= 'f'; push( @cmd, $self->{tar_read_options} ) if ( $self->{tar_read_options} ne '' ); return \@cmd; } sub _read_openbsd_opts { my ( $self, $compress_opt ) = @_; my @cmd; push( @cmd, $self->{tar} ); if ($compress_opt) { # actually, prepending '-' would work with any modern GNU tar $compress_opt = '-' . $compress_opt; push( @cmd, $compress_opt ); } push( @cmd, '-x' ); push( @cmd, $self->{tar_read_options} ) if ( $self->{tar_read_options} ne '' ); push( @cmd, @{ $self->{tar_gnu_read_options} } ) if ( scalar( @{ $self->{tar_gnu_read_options} } ) > 0 ); return \@cmd; } sub read { ## no critic (ProhibitBuiltinHomonyms) my ( $self, $tarfile, @files ) = @_; my $cwd = getcwd(); unless ( File::Spec::Functions::file_name_is_absolute($tarfile) ) { $tarfile = File::Spec::Functions::rel2abs( $tarfile, $cwd ); } chdir $self->{tardir} or LOGDIE "Cannot chdir to $self->{tardir}"; my $compr_opt = ''; # sane value $compr_opt = $self->is_compressed($tarfile); my @cmd; if ( $self->_is_openbsd ) { @cmd = @{ $self->_read_openbsd_opts($compr_opt) }; push @cmd, '-f'; } elsif ( $self->_is_solaris ) { @cmd = @{ $self->_read_solaris_opts($compr_opt) }; } else { @cmd = ( $self->{tar}, "${compr_opt}x$self->{tar_read_options}", @{ $self->{tar_gnu_read_options} }, '-f' ); } push( @cmd, $tarfile, @files ); $logger->debug("Running @cmd") if ( $logger->is_debug ); my $error_code = run( \@cmd, \my ( $in, $out, $err ) ); unless ($error_code) { ERROR "@cmd failed: $err"; chdir $cwd or LOGDIE "Cannot chdir to $cwd"; return; } $logger->warn($err) if ( $logger->is_warn and $err ); chdir $cwd or LOGDIE "Cannot chdir to $cwd: $!"; return ( $error_code == 0 ) ? undef : $error_code; } =head2 list_reset $arch->list_reset() Resets the list iterator. To be used before the first call to C. =cut sub list_reset { my ($self) = @_; #TODO: keep the file list as a fixed attribute of the instance my $list_file = File::Spec->catfile( $self->{objdir}, 'list' ); my $cwd = getcwd(); chdir $self->{tardir} or LOGDIE "Can't chdir to $self->{tardir}: $!"; open( my $fh, '>', $list_file ) or LOGDIE "Can't open $list_file: $!"; if ( $logger->is_debug ) { $logger->debug('List of all files identified inside the tar file'); } find( sub { my $entry = $File::Find::name; $entry =~ s#^\./##o; my $type = ( -d $_ ? 'd' : -l $_ ? 'l' : 'f' ); print $fh "$type $entry\n"; $logger->debug("$type $entry") if ( $logger->is_debug ); }, '.' ); $logger->debug('All entries listed') if ( $logger->is_debug ); close($fh); chdir $cwd or LOGDIE "Can't chdir to $cwd: $!"; $self->_offset(0); return 1; } sub _read_from_tar { my $self = shift; my ( $wtr, $rdr, $err ) = ( gensym, gensym, gensym ); my $pid = open3( $wtr, $rdr, $err, "$self->{tar} --version" ); my ( $output, $error ); { local $/ = undef; $output = <$rdr>; $error = <$err>; } close($rdr); close($err); close($wtr); waitpid( $pid, 0 ); chomp $error; chomp $output; $self->{tar_error_msg} = $error; $self->{version_info} = $output; $self->{tar_exit_code} = $? >> 8; return 1; } sub _acquire_tar_info { my ( $self, $skip ) = @_; $self->_read_from_tar() unless ($skip); my $bsd_regex = qr/bsd/i; $self->{is_gnu} = 0; $self->{is_bsd} = 0; if ( $self->_is_openbsd() ) { # there is no way to acquire version information from default tar program on OpenBSD $self->{version_info} = "Information not available on $Config{osname}"; $self->{tar_exit_code} = 0; $self->{is_bsd} = 1; } elsif ( $self->_is_solaris() ) { $self->{version_info} = "Information not available on $Config{osname}"; $self->{tar_exit_code} = 0; $self->{is_bsd} = 1; } elsif ( ( $self->{tar} =~ $bsd_regex ) and ( $self->{tar_exit_code} == 1 ) ) { # bsdtar exit code is 1 when asking for version, forcing to zero since is not an error $self->{tar_exit_code} = 0; $self->{is_bsd} = 1; } $self->{version_info} = 'Information not available. Search for errors' unless ( $self->{tar_exit_code} == 0 ); $self->{is_gnu} = 1 if ( $self->{version_info} =~ /GNU/ ); return 1; } sub _setup_mswin { my $self = shift; # bsdtar is always preferred on Windows my $tar_path = which('bsdtar'); $tar_path = which('tar') unless ( defined($tar_path) ); if ( $tar_path =~ /\s/ ) { # double quoting will be required is there is a space $tar_path = qq($tar_path); } $self->{tar} = $tar_path; } =head2 tardir $arch->tardir(); Return the directory the tarball was unpacked in. This is sometimes useful to play dirty tricks on B by mass-manipulating unpacked files before wrapping them back up into the tarball. =cut sub tardir { my ($self) = @_; return $self->{tardir}; } =head2 is_compressed Returns a string to identify if the tarball is compressed or not. Expect as parameter a string with the path to the tarball. Returns: =over =item * a "z" character if the file is compressed with gzip. =item * a "j" character if the file is compressed with bzip2. =item * a "" character if the file is not compressed at all. =back =cut sub is_compressed { my ( $self, $tarfile ) = @_; return 'z' if $tarfile =~ $self->{gzip_regex}; return 'j' if $tarfile =~ $self->{bzip2_regex}; # Sloppy check for gzip files open( my $fh, '<', $tarfile ) or croak("Cannot open $tarfile: $!"); binmode($fh); my $read = sysread( $fh, my $two, 2, 0 ) or croak("Cannot sysread $tarfile: $!"); close($fh); return 'z' if ( ( ( ord( substr( $two, 0, 1 ) ) ) == 0x1F ) and ( ( ord( substr( $two, 1, 1 ) ) ) == 0x8B ) ); return q{}; } =head2 locate $arch->locate($logic_path); Finds the physical location of a file, specified by C<$logic_path>, which is the virtual path of the file within the tarball. Returns a path to the temporary file B created to manipulate the tarball on disk. =cut sub locate { my ( $self, $rel_path ) = @_; my $real_path = File::Spec->catfile( $self->{tardir}, $rel_path ); if ( -e $real_path ) { $logger->debug("$real_path exists") if ( $logger->is_debug ); return $real_path; } else { $logger->warn("$rel_path not found in tarball") if ( $logger->is_warn ); return; } } =head2 add $arch->add($logic_path, $file_or_stringref, [$options]); Add a new file to the tarball. C<$logic_path> is the virtual path of the file within the tarball. C<$file_or_stringref> is either a scalar, in which case it holds the physical path of a file on disk to be transferred (i.e. copied) to the tarball, or it is a reference to a scalar, in which case its content is interpreted to be the data of the file. If no additional parameters are given, permissions and user/group id settings of a file to be added are copied. If you want different settings, specify them in the options hash: $arch->add($logic_path, $stringref, { perm => 0755, uid => 123, gid => 10 }); If $file_or_stringref is a reference to a Unicode string, the C option has to be set to make sure the string gets written as proper UTF-8 into the tarfile: $arch->add($logic_path, $stringref, { binmode => ":utf8" }); =cut sub add { my ( $self, $rel_path, $path_or_stringref, $opts ) = @_; if ($opts) { unless ( ( ref($opts) ) and ( ref($opts) eq 'HASH' ) ) { LOGDIE "Option parameter given to add() not a hashref."; } } my ( $perm, $uid, $gid, $binmode ); $perm = $opts->{perm} if defined $opts->{perm}; $uid = $opts->{uid} if defined $opts->{uid}; $gid = $opts->{gid} if defined $opts->{gid}; $binmode = $opts->{binmode} if defined $opts->{binmode}; my $target = File::Spec->catfile( $self->{tardir}, $rel_path ); my $target_dir = dirname($target); unless ( -d $target_dir ) { if ( ref($path_or_stringref) ) { $self->add( dirname($rel_path), dirname($target_dir) ); } else { $self->add( dirname($rel_path), dirname($path_or_stringref) ); } } if ( ref($path_or_stringref) ) { open my $fh, '>', $target or LOGDIE "Can't open $target: $!"; if ( defined $binmode ) { binmode $fh, $binmode; } print $fh $$path_or_stringref; close $fh; } elsif ( -d $path_or_stringref ) { # perms will be fixed further down mkpath( $target, 0, oct(755) ) unless -d $target; } else { copy $path_or_stringref, $target or LOGDIE "Can't copy $path_or_stringref to $target ($!)"; } if ( defined $uid ) { chown $uid, -1, $target or LOGDIE "Can't chown $target uid to $uid ($!)"; } if ( defined $gid ) { chown -1, $gid, $target or LOGDIE "Can't chown $target gid to $gid ($!)"; } if ( defined $perm ) { chmod $perm, $target or LOGDIE "Can't chmod $target to $perm ($!)"; } if ( not defined $uid and not defined $gid and not defined $perm and not ref($path_or_stringref) ) { perm_cp( $path_or_stringref, $target ) or LOGDIE "Can't perm_cp $path_or_stringref to $target ($!)"; } return 1; } =head2 perm_cp Copies the permissions from a file to another. Expects as parameters: =over =item 1. string of the path to the file which permissions will be copied from. =item 2. string of the path to the file which permissions will be copied to. =back Returns 1 if everything works as expected. =cut sub perm_cp { my ( $source, $target ) = @_; perm_set( $target, perm_get($source) ); return 1; } =head2 perm_get Gets the permissions from a file. Expects as parameter the path to the source file. Returns an array reference with only the permissions values, as returned by C. =cut sub perm_get { my ($filename) = @_; my @stats = ( stat $filename )[ 2, 4, 5 ] or LOGDIE "Cannot stat $filename ($!)"; return \@stats; } =head2 perm_set Sets the permission on a file. Expects as parameters: =over =item 1. The path to the file where the permissions should be applied to. =item 2. An array reference with the permissions (see C) =back Returns 1 if everything goes fine. Ignore errors here, as we can't change uid/gid unless we're the superuser (see LIMITATIONS section). =cut sub perm_set { my ( $filename, $perms ) = @_; chown( $perms->[1], $perms->[2], $filename ); chmod( $perms->[0] & oct(777), $filename ) or LOGDIE "Cannot chmod $filename ($!)"; return 1; } =head2 remove $arch->remove($logic_path); Removes a file from the tarball. C<$logic_path> is the virtual path of the file within the tarball. =cut sub remove { my ( $self, $rel_path ) = @_; my $target = File::Spec->catfile( $self->{tardir}, $rel_path ); rmtree($target) or LOGDIE "Can't rmtree $target: $!"; return 1; } =head2 list_all my $items = $arch->list_all(); Returns a reference to a (possibly huge) array of items in the tarfile. Each item is a reference to an array, containing two elements: the relative path of the item in the tarfile and the physical path to the unpacked file or directory on disk. To iterate over the list, the following construct can be used: # Get a huge list with all entries for my $entry (@{$arch->list_all()}) { my($tar_path, $real_path) = @$entry; print "Tarpath: $tar_path Tempfile: $real_path\n"; } If the list of items in the tarfile is big, use C and C instead of C. =cut sub list_all { my ($self) = @_; my @entries = (); $self->list_reset(); while ( my $entry = $self->list_next() ) { push @entries, $entry; } return \@entries; } =head2 list_next my ($tar_path, $phys_path, $type) = $arch->list_next(); Returns the next item in the tarfile. It returns a list of three scalars: the relative path of the item in the tarfile, the physical path to the unpacked file or directory on disk, and the type of the entry (f=file, d=directory, l=symlink). Note that by default, B won't display directories, unless the C parameter is set when running the constructor. =cut sub list_next { my ($self) = @_; my $offset = $self->_offset(); my $list_file = File::Spec->catfile( $self->{objdir}, 'list' ); open my $fh, '<', $list_file or LOGDIE "Can't open $list_file: $!"; seek $fh, $offset, 0; my $data; REDO: { my $line = <$fh>; unless ( defined($line) ) { close($fh); } else { chomp $line; my ( $type, $entry ) = split / /, $line, 2; redo if ( ( $type eq 'd' ) and ( not $self->{dirs} ) ); $self->_offset( tell $fh ); close($fh); $data = [ $entry, File::Spec->catfile( $self->{tardir}, $entry ), $type ]; } } return $data; } sub _offset { my ( $self, $new_offset ) = @_; my $offset_file = File::Spec->catfile( $self->{objdir}, "offset" ); if ( defined $new_offset ) { open my $fh, '>', $offset_file or LOGDIE "Can't open $offset_file: $!"; print $fh "$new_offset\n"; close $fh; } open my $fh, '<', $offset_file or LOGDIE "Can't open $offset_file: $! (Did you call list_next() without a previous list_reset()?)"; my $offset = <$fh>; chomp $offset; close $fh; return $offset; } =head2 write $arch->write($tarfile, $compress); Write out the tarball by tarring up all temporary files and directories and store it in C<$tarfile> on disk. If C<$compress> holds a true value, compression is used. =cut sub write { ## no critic (ProhibitBuiltinHomonyms) my ( $self, $tarfile, $compress ) = @_; my $cwd = getcwd(); chdir $self->{tardir} or LOGDIE "Can't chdir to $self->{tardir}: $!"; unless ( File::Spec::Functions::file_name_is_absolute($tarfile) ) { $tarfile = File::Spec::Functions::rel2abs( $tarfile, $cwd ); } my $compr_opt = ''; $compr_opt = 'z' if $compress; opendir( my $dir, '.' ) or LOGDIE "Cannot open $self->{tardir}: $!"; my @top_entries = readdir($dir); closedir($dir); $self->_rem_dots( \@top_entries ); my $cmd = [ $self->{tar}, "${compr_opt}cf$self->{tar_write_options}", $tarfile, @{ $self->{tar_gnu_write_options} } ]; if ( @top_entries > $self->{max_cmd_line_args} ) { my $filelist_file = $self->{tmpdir} . "/file-list"; open( my $fh, '>', $filelist_file ) or LOGDIE "Cannot write to $filelist_file: $!"; for my $entry (@top_entries) { print $fh "$entry\n"; } close($fh); push @$cmd, "-T", $filelist_file; } else { push @$cmd, @top_entries; } $logger->debug("Running @$cmd") if ( $logger->is_debug ); my $rc = run( $cmd, \my ( $in, $out, $err ) ); unless ($rc) { ERROR "@$cmd failed: $err"; chdir $cwd or LOGDIE "Cannot chdir to $cwd"; return; } WARN $err if $err; chdir $cwd or LOGDIE "Cannot chdir to $cwd"; return 1; } sub _rem_dots { my ( $self, $entries_ref ) = @_; my ( $first, $second ); my $index = 0; my $found = 0; for ( @{$entries_ref} ) { if ( ( length($_) <= 2 ) and ( ( $_ eq '.' ) or ( $_ eq '..' ) ) ) { if ( $found < 1 ) { $first = $index; $found++; $index++; next; } else { $second = $index; last; } } else { $index++; } } splice( @{$entries_ref}, $first, 1 ); # array length is now shortened by one splice( @{$entries_ref}, ( $second - 1 ), 1 ); return 1; } sub DESTROY { my ($self) = @_; $self->ramdisk_unmount() if defined $self->{ramdisk}; rmtree( $self->{objdir} ) if defined $self->{objdir}; rmtree( $self->{tmpdir} ) if defined $self->{tmpdir}; return 1; } =head2 is_gnu $arch->is_gnu(); Checks if the tar executable is a GNU tar by running 'tar --version' and parsing the output for "GNU". Returns true or false (in Perl terms). =cut sub is_gnu { return shift->{is_gnu}; } =head2 is_bsd $arch->is_bsd(); Same as C, but for BSD. =cut sub is_bsd { return shift->{is_bsd}; } =head2 ramdisk_mount Mounts a RAM disk. It executes the C program under the hood to mount a RAM disk. Expects as parameter a hash with options to mount the RAM disk, like: =over =item * size =item * type (most probably C) =item * tmpdir =back Returns 1 if everything goes fine. Be sure to check the L for full details on using RAM disks. =cut sub ramdisk_mount { my ( $self, %options ) = @_; # mkdir -p /mnt/myramdisk # mount -t tmpfs -o size=20m tmpfs /mnt/myramdisk $self->{mount} = which("mount") unless $self->{mount}; $self->{umount} = which("umount") unless $self->{umount}; for (qw(mount umount)) { unless ( defined $self->{$_} ) { LOGWARN "No $_ command found in PATH"; return; } } $self->{ramdisk} = {%options}; $self->{ramdisk}->{size} = "100m" unless defined $self->{ramdisk}->{size}; if ( !defined $self->{ramdisk}->{tmpdir} ) { $self->{ramdisk}->{tmpdir} = tempdir( CLEANUP => 1 ); } my @cmd = ( $self->{mount}, "-t", "tmpfs", "-o", "size=$self->{ramdisk}->{size}", "tmpfs", $self->{ramdisk}->{tmpdir} ); INFO "Mounting ramdisk: @cmd"; my $rc = system(@cmd); if ($rc) { if ( $logger->is_info ) { $logger->info("Mount command '@cmd' failed: $?"); $logger->info('Note that this only works on Linux and as root'); } return; } $self->{ramdisk}->{mounted} = 1; return 1; } =head2 ramdisk_unmount Unmounts the RAM disk already mounted with C. Don't expect parameters and returns 1 if everything goes fine. Be sure to check the L for full details on using RAM disks. =cut sub ramdisk_unmount { my ($self) = @_; return unless ( exists $self->{ramdisk}->{mounted} ); my @cmd = ( $self->{umount}, $self->{ramdisk}->{tmpdir} ); $logger->info("Unmounting ramdisk: @cmd") if ( $logger->is_info ); my $rc = system(@cmd); if ($rc) { LOGWARN "Unmount command '@cmd' failed: $?"; return; } delete $self->{ramdisk}; return 1; } 1; __END__ =head1 Using RAM Disks On Linux, it's quite easy to create a RAM disk and achieve tremendous speedups while untarring or modifying a tarball. You can either create the RAM disk by hand by running # mkdir -p /mnt/myramdisk # mount -t tmpfs -o size=20m tmpfs /mnt/myramdisk and then feeding the ramdisk as a temporary directory to B, like my $tar = Archive::Tar::Wrapper->new( tmpdir => '/mnt/myramdisk' ); or using B's built-in option C: my $tar = Archive::Tar::Wrapper->new( ramdisk => { type => 'tmpfs', size => '20m', # 20 MB }, ); Only drawback with the latter option is that creating the RAM disk needs to be performed as root, which often isn't desirable for security reasons. For this reason, B offers a utility functions that mounts the RAM disk and returns the temporary directory it's located in: # Create new ramdisk (as root): my $tmpdir = Archive::Tar::Wrapper->ramdisk_mount( type => 'tmpfs', size => '20m', # 20 MB ); # Delete a ramdisk (as root): Archive::Tar::Wrapper->ramdisk_unmount(); Optionally, the C command accepts a C parameter pointing to a temporary directory for the RAM disk if you wish to set it yourself instead of letting B create it automatically. =head1 KNOWN LIMITATIONS =over =item * Currently, only C programs supporting the C option (for compressing/decompressing) are supported. Future version will use C alternatively. =item * Currently, you can't add empty directories to a tarball directly. You could add a temporary file within a directory, and then C the file. =item * If you delete a file, the empty directories it was located in stay in the tarball. You could try to C them and delete them. This will be fixed, though. =item * Filenames containing newlines are causing problems with the list iterators. To be fixed. =item * If you ask B to add a file to a tarball, it copies it into a temporary directory and then calls the system tar to wrap up that directory into a tarball. This approach has limitations when it comes to file permissions: If the file to be added belongs to a different user/group, B will adjust the uid/gid/permissions of the target file in the temporary directory to reflect the original file's settings, to make sure the system tar will add it like that to the tarball, just like a regular tar run on the original file would. But this will fail of course if the original file's uid is different from the current user's, unless the script is running with superuser rights. The tar program by itself (without B) works differently: It'll just make a note of a file's uid/gid/permissions in the tarball (which it can do without superuser rights) and upon extraction, it'll adjust the permissions of newly generated files if the -p option is given (default for superuser). =back =head1 BUGS B doesn't currently handle filenames with embedded newlines. =head2 Microsoft Windows support Support on Microsoft Windows is limited. Versions below Windows 10 will not be supported for desktops, and for servers only Windows 2012 and above. The GNU C program doesn't work properly with the current interface of B. You must use the C and make sure it appears first in the C environment variable than the GNU tar (if it is installed). See L for details about how to download and install C, or go to L for a direct download. Be sure to look for the C program package to install it as well. Windows 10 might come already with C program already installed. Please search for that on the appropriate page (Microsoft keeps changing the link to keep track of it here). Having spaces in the path string to the tar program might be an issue too. Although there is some effort in terms of workaround it, you best might avoid it completely by installing in a different path than C. Installing both C and C in C will probably be enough when running the installers. =head1 LEGALESE This software is copyright (c) 2005 of Mike Schilli. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Archive-Tar-Wrapper. If not, see L. =head1 SEE ALSO =over =item * Linux Gazette article from Ben Okopnik, L. =back =head1 AUTHOR 2005, Mike Schilli =head1 MAINTAINER 2018, Alceu Rodrigues de Freitas Junior =cut Archive-Tar-Wrapper-0.41/META.json0000664000175000017500000000351214631574755015572 0ustar alceualceu{ "abstract" : "API wrapper around the 'tar' utility", "author" : [ "Mike Schilli ", "Alceu Rodrigues de Freitas Junior " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010", "license" : [ "gpl_3" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Archive-Tar-Wrapper", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0", "File::Which" : "0" } }, "runtime" : { "requires" : { "CPAN::Meta" : "0", "Cwd" : "0", "File::Temp" : "0", "File::Which" : "0", "IPC::Run" : "0", "Log::Log4perl" : "0", "perl" : "5.008001" } }, "test" : { "requires" : { "Dumbbench" : "0.503", "Test::Simple" : "1.302073" } } }, "provides" : { "Archive::Tar::Wrapper" : { "file" : "lib/Archive/Tar/Wrapper.pm", "version" : "0.41" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/glasswalk3r/archive-tar-wrapper-perl/issues" }, "repository" : { "type" : "git", "url" : "https://github.com/glasswalk3r/archive-tar-wrapper-perl.git", "web" : "https://github.com/glasswalk3r/archive-tar-wrapper-perl" } }, "version" : "0.41", "x_serialization_backend" : "JSON::PP version 4.16" } Archive-Tar-Wrapper-0.41/Makefile.PL0000644000175000017500000000736514607355261016123 0ustar alceualceuuse warnings; use strict; use ExtUtils::MakeMaker; use File::Which; if ( $^O eq 'MSWin32' ) { require Win32; my $product_info = Win32::GetOSDisplayName(); my ( $osvername, $major, $minor, $id ) = Win32::GetOSVersion(); print "Running on $product_info - major=$major, minor=$minor, id=$id\n"; unless ( $major >= 6 ) { warn "Too old Microsoft Windows to be supported, major version must be equal or higher 6.\n"; die "OS unsupported\n"; } # double quoting is required on Windows if there are spaces in the path my $tar_path = which('bsdtar.exe'); $tar_path = which('tar') unless ( defined($tar_path) ); unless ( defined($tar_path) ) { warn "No tar program available, cannot work without it.\n"; die "OS unsupported\n"; } else { $tar_path = qq{$tar_path} if ( $tar_path =~ /\s/ ); my $version_info = `$tar_path --version`; print "Using $tar_path $version_info\n"; if ( $version_info =~ /GNU/ ) { warn "Sorry, GNU tar is not supported on Microsoft Windows. Install a BSD tar or check your PATH configuration\n"; die "OS unsupported\n"; } } } my ( $module_path, $module_version ); { require ExtUtils::MY; my $version_reader = MM->new(); $module_path = 'lib/Archive/Tar/Wrapper.pm'; $module_version = $version_reader->parse_version("./$module_path"); } my %WriteMakefileArgs = ( 'NAME' => 'Archive::Tar::Wrapper', 'VERSION' => $module_version, 'MIN_PERL_VERSION' => 5.008001, 'NO_META' => 0, 'NO_MYMETA' => 0, 'LICENSE' => 'gpl_3', 'PREREQ_PM' => { 'File::Temp' => 0, 'Cwd' => 0, 'Log::Log4perl' => 0, 'IPC::Run' => 0, 'File::Which' => 0, 'CPAN::Meta' => 0 }, 'ABSTRACT_FROM' => 'lib/Archive/Tar/Wrapper.pm' ); if ( $ExtUtils::MakeMaker::VERSION >= 6.46 ) { $WriteMakefileArgs{META_MERGE} = { provides => { 'Archive::Tar::Wrapper' => { file => $module_path, version => $module_version } } }; } if ( $ExtUtils::MakeMaker::VERSION >= 6.50 ) { $WriteMakefileArgs{META_MERGE}->{'meta-spec'} = { 'version' => '2', 'url' => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec', 'release_status' => 'stable' }; $WriteMakefileArgs{META_MERGE}->{'resources'} = { 'bugtracker' => { 'web' => 'https://github.com/glasswalk3r/archive-tar-wrapper-perl/issues', }, 'repository' => { 'type' => 'git', 'url' => 'https://github.com/glasswalk3r/archive-tar-wrapper-perl.git', 'web' => 'https://github.com/glasswalk3r/archive-tar-wrapper-perl', } }; } if ( $ExtUtils::MakeMaker::VERSION >= 6.52 ) { $WriteMakefileArgs{CONFIGURE_REQUIRES} = { 'ExtUtils::MakeMaker' => 0, 'File::Which' => 0, }; } # Test::More::is_deeply is required for testing if ( $ExtUtils::MakeMaker::VERSION >= 6.64 ) { $WriteMakefileArgs{TEST_REQUIRES}->{'Test::Simple'} = 1.302073; $WriteMakefileArgs{TEST_REQUIRES}->{'Dumbbench'} = 0.503; } else { $WriteMakefileArgs{PREREQ_PM}->{'Test::Simple'} = 1.302073; $WriteMakefileArgs{PREREQ_PM}->{'Dumbbench'} = 0.503; } if ( $] >= 5.005 ) { $WriteMakefileArgs{ABSTRACT_FROM} = 'lib/Archive/Tar/Wrapper.pm'; $WriteMakefileArgs{AUTHOR} = [ 'Mike Schilli ', 'Alceu Rodrigues de Freitas Junior ' ]; } delete $WriteMakefileArgs{LICENSE} if ( $ExtUtils::MakeMaker::VERSION < 6.31 ); WriteMakefile(%WriteMakefileArgs); Archive-Tar-Wrapper-0.41/META.yml0000664000175000017500000000205114631574755015417 0ustar alceualceu--- abstract: "API wrapper around the 'tar' utility" author: - 'Mike Schilli ' - 'Alceu Rodrigues de Freitas Junior ' build_requires: Dumbbench: '0.503' ExtUtils::MakeMaker: '0' Test::Simple: '1.302073' configure_requires: ExtUtils::MakeMaker: '0' File::Which: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010' license: gpl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Archive-Tar-Wrapper no_index: directory: - t - inc provides: Archive::Tar::Wrapper: file: lib/Archive/Tar/Wrapper.pm version: '0.41' requires: CPAN::Meta: '0' Cwd: '0' File::Temp: '0' File::Which: '0' IPC::Run: '0' Log::Log4perl: '0' perl: '5.008001' resources: bugtracker: https://github.com/glasswalk3r/archive-tar-wrapper-perl/issues repository: https://github.com/glasswalk3r/archive-tar-wrapper-perl.git version: '0.41' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Archive-Tar-Wrapper-0.41/LICENSE0000644000175000017500000010451314607331411015136 0ustar alceualceu GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . Archive-Tar-Wrapper-0.41/MANIFEST.SKIP0000644000175000017500000000014714607331411016025 0ustar alceualceublib ^Makefile$ ^Makefile.old$ CVS .cvsignore docs MANIFEST.bak adm/release .git ^MYMETA\.(json|yaml)$ Archive-Tar-Wrapper-0.41/CONTRIBUTING.md0000644000175000017500000000115314607331411016356 0ustar alceualceu# CONTRIBUTING Contributing to this project is easy. First you need to fork this repository. It will be much easier if you have a free Github account. When done, just hit: ``` $ git clone https://github.com//archive-tar-wrapper-perl.git ``` Or whatever you prefer to do to clone a git repository. From there you can modify or create new files. When you finished, you then can create a pull request to this project. Just keep in mind to use Perltidy with your files in order to format them. That's exactly what is here, and with default configurations. That's it! Thanks for contributing! Archive-Tar-Wrapper-0.41/xt/0000755000175000017500000000000014631574755014601 5ustar alceualceuArchive-Tar-Wrapper-0.41/xt/lib/0000755000175000017500000000000014631574755015347 5ustar alceualceuArchive-Tar-Wrapper-0.41/xt/lib/ATWDumbbench.pm0000644000175000017500000000250214607342532020134 0ustar alceualceupackage ATWDumbbench; use strict; use warnings; use parent 'Dumbbench'; sub new { my ( $class, @args ) = @_; my $self = $class->SUPER::new(@args); $self->{atw_measure_map} = {}; return $self; } sub measurements { my $self = shift; return ( sort { $a <=> $b } values( %{ $self->{atw_measure_map} } ) )[0]; } sub get_measure { my ( $self, $name ) = @_; return $self->{atw_measure_map}->{$name}; } sub get_map { my ($self) = @_; return $self->{atw_measure_map}; } sub report_as_text { my ($self) = @_; my $formatted; foreach my $instance ( $self->instances ) { my $result = $instance->result; my $result_str = Dumbbench::unscientific_notation($result); my $mean = $result->raw_number; my $sigma = $result->raw_error->[0]; my $name = $instance->_name_prefix; $self->{atw_measure_map}->{ $instance->name } = $result->number; $formatted .= sprintf( "%sRan %u iterations (%u outliers).\n", $name, scalar( @{ $instance->timings } ), scalar( @{ $instance->timings } ) - $result->nsamples ); $formatted .= sprintf( "%sRounded run time per iteration: %s (%.1f%%)\n", $name, $result_str, $sigma / $mean * 100 ); } return $formatted; } 1; Archive-Tar-Wrapper-0.41/xt/performance-small.t0000644000175000017500000001124314607353116020363 0ustar alceualceuuse warnings; use strict; use File::Temp qw(tempfile tempdir); use Test::More tests => 1; use lib 'xt/lib'; use ATWDumbbench; use constant BATCH_SIZE => 1000; use constant TOTAL_FILES => 10; my $bench = ATWDumbbench->new( target_rel_precision => 0.005, initial_runs => BATCH_SIZE, ); my $dir = tempdir( CLEANUP => 1 ); my $template = 'foobar-XXXXXXXX'; for ( 1 .. TOTAL_FILES ) { my ( $fh, $filename ) = tempfile( $template, DIR => $dir ); print $fh rand(); close($fh); } my $regex = qr/^\.\.?$/; $bench->add_instances( Dumbbench::Instance::PerlSub->new( name => 'with grep', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @top_entries = grep { $_ !~ /^\.\.?$/ } readdir $dir_h; closedir($dir_h); } ), Dumbbench::Instance::PerlSub->new( name => 'with grep and compiled regex', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @top_entries = grep { $_ !~ $regex } readdir $dir_h; closedir($dir_h); } ), Dumbbench::Instance::PerlSub->new( name => 'with eq', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @temp = readdir($dir_h); closedir($dir_h); my @top_entries; for (@temp) { next if ( ( $_ eq '.' ) or ( $_ eq '..' ) ); push( @top_entries, $_ ); } } ), Dumbbench::Instance::PerlSub->new( name => 'with enhanced eq', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @temp = readdir($dir_h); closedir($dir_h); my @top_entries; for (@temp) { next if ( ( length($_) <= 2 ) and ( ( $_ eq '.' ) or ( $_ eq '..' ) ) ); push( @top_entries, $_ ); } } ), Dumbbench::Instance::PerlSub->new( name => 'with enhanced eq mark2', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @temp = readdir($dir_h); closedir($dir_h); my @top_entries; my $counter = 0; my $found = 0; for (@temp) { $counter++; if ( ( length($_) <= 2 ) and ( ( $_ eq '.' ) or ( $_ eq '..' ) ) ) { $found++; if ( $found < 2 ) { next; } else { push( @top_entries, splice( @temp, $counter ) ); last; } } push( @top_entries, $_ ); } } ), Dumbbench::Instance::PerlSub->new( name => 'with enhanced eq mark3', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @temp = readdir($dir_h); closedir($dir_h); my ( $first, $second ); my $index = 0; my $found = 0; for (@temp) { if ( ( length($_) <= 2 ) and ( ( $_ eq '.' ) or ( $_ eq '..' ) ) ) { if ( $found < 1 ) { $first = $index; $found++; $index++; next; } else { $second = $index; last; } } else { $index++; } } splice( @temp, $first, 1, 1 ); splice( @temp, $second, 1, 1 ); } ), Dumbbench::Instance::PerlSub->new( name => 'sort and shift', code => sub { opendir( my $dir_h, $dir ) or die "Cannot open $dir: $!"; my @top_entries = readdir($dir_h); closedir($dir_h); @top_entries = sort(@top_entries); # removing the '.' and '..' entries shift(@top_entries); shift(@top_entries); } ), ); note('This will take a while... hang on.'); $bench->run; diag( $bench->report_as_text ); TODO: { local $TODO = 'Too many variables to account for success'; # See https://metacpan.org/pod/Number::WithError#full_cmp my $method_name = 'with enhanced eq mark3'; cmp_ok( $bench->measurements(), '<=', $bench->get_measure($method_name), "'$method_name' is the fastest methods." ); } Archive-Tar-Wrapper-0.41/xt/performance.t0000644000175000017500000001074614607353116017264 0ustar alceualceuuse warnings; use strict; use File::Temp qw(tempfile tempdir); use Test::More tests => 1; use lib 'xt/lib'; use ATWDumbbench; use constant BATCH_SIZE => 1000; my $bench = ATWDumbbench->new( target_rel_precision => 0.005, initial_runs => BATCH_SIZE, ); my $dir = tempdir( CLEANUP => 1 ); my $template = 'foobar-XXXXXXXX'; for ( 1 .. BATCH_SIZE ) { my ( $fh, $filename ) = tempfile( $template, DIR => $dir ); print $fh rand(); close($fh); } my $regex = qr/^\.\.?$/; $bench->add_instances( Dumbbench::Instance::PerlSub->new( name => 'with grep', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @top_entries = grep { $_ !~ /^\.\.?$/ } readdir $dir_h; closedir($dir_h); } ), Dumbbench::Instance::PerlSub->new( name => 'with grep and compiled regex', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @top_entries = grep { $_ !~ $regex } readdir $dir_h; closedir($dir_h); } ), Dumbbench::Instance::PerlSub->new( name => 'with eq', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @temp = readdir($dir_h); closedir($dir_h); my @top_entries; for (@temp) { next if ( ( $_ eq '.' ) or ( $_ eq '..' ) ); push( @top_entries, $_ ); } } ), Dumbbench::Instance::PerlSub->new( name => 'with enhanced eq', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @temp = readdir($dir_h); closedir($dir_h); my @top_entries; for (@temp) { next if ( ( length($_) <= 2 ) and ( ( $_ eq '.' ) or ( $_ eq '..' ) ) ); push( @top_entries, $_ ); } } ), Dumbbench::Instance::PerlSub->new( name => 'with enhanced eq mark2', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @temp = readdir($dir_h); closedir($dir_h); my @top_entries; my $counter = 0; my $found = 0; for (@temp) { $counter++; if ( ( length($_) <= 2 ) and ( ( $_ eq '.' ) or ( $_ eq '..' ) ) ) { $found++; if ( $found < 2 ) { next; } else { push( @top_entries, splice( @temp, $counter ) ); last; } } push( @top_entries, $_ ); } } ), Dumbbench::Instance::PerlSub->new( name => 'with enhanced eq mark3', code => sub { opendir my $dir_h, $dir or die "Cannot open $dir: $!"; my @temp = readdir($dir_h); closedir($dir_h); my ( $first, $second ); my $index = 0; my $found = 0; for (@temp) { if ( ( length($_) <= 2 ) and ( ( $_ eq '.' ) or ( $_ eq '..' ) ) ) { if ( $found < 1 ) { $first = $index; $found++; $index++; next; } else { $second = $index; last; } } else { $index++; } } splice( @temp, $first, 1 ); splice( @temp, ( $second - 1 ), 1 ); } ), Dumbbench::Instance::PerlSub->new( name => 'sort and shift', code => sub { opendir( my $dir_h, $dir ) or die "Cannot open $dir: $!"; my @top_entries = readdir($dir_h); closedir($dir_h); @top_entries = sort(@top_entries); # removing the '.' and '..' entries shift(@top_entries); shift(@top_entries); } ), ); note('This will take a while... hang on.'); $bench->run; diag( $bench->report_as_text ); my $method_name = 'with enhanced eq mark3'; cmp_ok( $bench->measurements(), '<=', $bench->get_measure($method_name), "'$method_name' is the fastest method." ); Archive-Tar-Wrapper-0.41/MANIFEST0000644000175000017500000000102414631574755015274 0ustar alceualceuChanges eg/tarflat lib/Archive/Tar/Wrapper.pm LICENSE Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.yml Module meta-data (added by MakeMaker) t/001Basic.t t/002Mult.t t/003Dirs.t t/004Utf8.t t/005Cwd.t t/006DirPerms.t t/007bzip.t t/009compressed.t t/010openbsd.t t/011remdots.t t/012tarinfo.t t/data/bar.tar t/data/foo.tar.bz2 t/data/foo.tgz xt/lib/ATWDumbbench.pm xt/performance.t xt/performance-small.t README.md CONTRIBUTING.md META.json Module JSON meta-data (added by MakeMaker) Archive-Tar-Wrapper-0.41/eg/0000755000175000017500000000000014631574755014541 5ustar alceualceuArchive-Tar-Wrapper-0.41/eg/tarflat0000755000175000017500000000433214607334047016115 0ustar alceualceu#!/usr/bin/perl use strict; use warnings; use Getopt::Std; use Pod::Usage; use Archive::Tar::Wrapper; use Sysadm::Install qw(:all); use vars qw($CVSVERSION); $CVSVERSION = '$Revision: 1.1 $'; getopts( "hv", \my %opts ); pod2usage() if $opts{h}; if ( $opts{v} ) { my ($version) = $CVSVERSION =~ /(\d\S+)/; die "$0 $version\n"; } my ( $target_dir, @tarfiles ) = @ARGV; unless ( defined($target_dir) or @tarfiles ) { pod2usage("Wrong number of arguments"); } unless ( -d $target_dir ) { my $create = ask "$target_dir doesn't exist. Create it [y]", "y"; mkd $target_dir if $create =~ /[yY]/; } my $arch = Archive::Tar::Wrapper->new(); for my $tarfile (@tarfiles) { $arch->read($tarfile); } $arch->list_reset(); while ( my $entry = $arch->list_next() ) { my ( $tar_path, $phys_path ) = @$entry; if ( -f $phys_path ) { cp $phys_path, $target_dir; } } __END__ =head1 NAME tarflat - Unpack tarfiles and put their content flat in a single directory =head1 SYNOPSIS tarflat target_dir tarfile ... =head1 OPTIONS =over 8 =item B<-h> Prints this manual page in text format. =item B<-v> Prints the script version. =back =head1 DESCRIPTION C =head1 EXAMPLES # Unpack foo.tgz and bar.tgz and store all of their files # (anywhere in the directory hierarchy) in the directory # /tmp/junk. $ mkdir /tmp/junk $ tarflat /tmp/junk foo.tgz bar.tgz =head1 LEGALESE This software is copyright (c) 2005 of Mike Schilli. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Archive-Tar-Wrapper. If not, see L. =head1 AUTHOR 2005, Mike Schilli =head1 MAINTAINER 2018, Alceu Rodrigues de Freitas Junior =cut