Skip Menu |

This queue is for tickets about the Archive-Tar CPAN distribution.

Report information
The Basics
Id: 11342
Status: resolved
Priority: 0/
Queue: Archive-Tar

People
Owner: Nobody in particular
Requestors: fischer.doug [...] grantstreet.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.23
Fixed in: (no value)



Subject: _extract_file() creates extraneous directory for single file extraction
The extract_file() method of Archive::Tar allows for the selective extraction of an archive member (file or directory), with the option to specify an alternate full path name (including filename) for the member. However, as currently coded, in the case of an individual file if an alternate path is specified the filename itself is created as a directory with the file itself (properly named) then under that directory. e.g. extract_file('foo/bar', 'my/file') where 'bar' is a file will create the contents of 'bar' as 'my/file/file' instead of as 'my/file'. This is easily remedied with a one-line patch: --- Archive-Tar-1.23.orig/lib/Archive/Tar.pm Fri Dec 3 09:37:45 2004 +++ Archive-Tar-1.23/lib/Archive/Tar.pm Wed Feb 2 12:06:40 2005 @@ -471,7 +471,7 @@ my $dir; ### is $name an absolute path? ### if( File::Spec->file_name_is_absolute( $name ) ) { - $dir = $name; + $dir = $dirs; ### it's a relative path ### } else {
[guest - Wed Feb 2 12:12:33 2005]: Show quoted text
> The extract_file() method of Archive::Tar allows for the selective > extraction of an archive member (file or directory), with the > option to specify an alternate full path name (including filename) > for the member. > > However, as currently coded, in the case of an individual file if an > alternate path is specified the filename itself is created as a > directory with the file itself (properly named) then under that > directory. > > e.g. extract_file('foo/bar', 'my/file') where 'bar' is a file will > create the contents of 'bar' as 'my/file/file' instead of as > 'my/file'. > > This is easily remedied with a one-line patch: > > --- Archive-Tar-1.23.orig/lib/Archive/Tar.pm Fri Dec 3 09:37:45 > 2004 > +++ Archive-Tar-1.23/lib/Archive/Tar.pm Wed Feb 2 12:06:40 2005 > @@ -471,7 +471,7 @@ > my $dir; > ### is $name an absolute path? ### > if( File::Spec->file_name_is_absolute( $name ) ) { > - $dir = $name; > + $dir = $dirs; > > ### it's a relative path ### > } else {
Although this sounds like a reasonable report, i've tried first to create a failing test case, and i've not succeeded.... Here's what i added as extra test code, and the result it produces: ### alternate extract path tests { my $outpath = File::Spec->catdir( @ROOT ); my $outfile = File::Spec->catfile( $outpath, $$ ); ok( $tar->extract_file( $file->full_path, $outfile ), " Extracted file '$path' to $outfile" ); ok( -e $outfile, " Extracted file '$outfile' exists" ); print `find $outpath -type f`; rm( $outfile ) unless $NO_UNLINK; } part of the output: ok 421 - Extracted 'src/long/out.tar' with 'extract' ok 422 - Expected file found ok 423 - File 'x/k' exists ok 424 - Opening file ok 425 - Contents OK ok 426 - Extracted file 'x/k' to src/long/11491 ok 427 - Extracted file 'src/long/11491' exists src/long/11491 src/long/b src/long/bar.tar src/long/foo.tgz src/long/out.tar I think this describes your problem... if it doesn't, or if you do get this fail where i dont, perhaps you can send me a sample program that demonstrates this failure.
From: Douglas K. Fischer (fischer.doug AT grantstreet.com)
[KANE - Tue Feb 22 07:50:23 2005]: Show quoted text
> Although this sounds like a reasonable report, i've tried first to > create a failing test case, and > i've not succeeded.... Here's what i added as extra test code, and the > result it produces: > > ### alternate extract path tests > { my $outpath = File::Spec->catdir( @ROOT ); > my $outfile = File::Spec->catfile( $outpath, $$ ); > > ok( $tar->extract_file( $file->full_path, $outfile ), > " Extracted file '$path' to $outfile" ); > ok( -e $outfile, " Extracted file '$outfile' exists" ); > > print `find $outpath -type f`; > rm( $outfile ) unless $NO_UNLINK; > > } > > part of the output: > > ok 421 - Extracted 'src/long/out.tar' with 'extract' > ok 422 - Expected file found > ok 423 - File 'x/k' exists > ok 424 - Opening file > ok 425 - Contents OK > ok 426 - Extracted file 'x/k' to src/long/11491 > ok 427 - Extracted file 'src/long/11491' exists > src/long/11491 > src/long/b > src/long/bar.tar > src/long/foo.tgz > src/long/out.tar > > I think this describes your problem... if it doesn't, or if you do get > this fail where i dont, > perhaps you can send me a sample program that demonstrates this > failure.
The think the reason the test code didn't reproduce it is the bug only happens if the specified alternate path is absolute, not relative. @ROOT in the test code contains the relative path 't/src/long'. The test case I used is: $ cd /tmp $ mkdir old $ touch old/file $ tar czvf tarball.tar.gz old/ $ perl attest.pl ----- attest.pl ----- #!/usr/bin/perl -w use strict; use Archive::Tar (); my $tarball = "/tmp/tarball.tar.gz"; my $tar = Archive::Tar->new($tarball); my $old = "old/file"; my $new = "/tmp/new/name"; $tar->extract_file($old, $new); exit(0); ----- END ----- $ find old old old/file $ find new new new/name new/name/name Hope this helps. Thanks, Doug
[guest - Fri Apr 1 14:34:27 2005]: Show quoted text
> The think the reason the test code didn't reproduce it is the bug only > happens if the specified alternate path is absolute, not relative. @ROOT > in the test code contains the relative path 't/src/long'.
[...] Show quoted text
> Hope this helps.
It sure did.. sorry for the slow response, but this bug is now fixed with commit 12035, and tests added to ensure it doesn't occur again. Release 1.24 will hold this fix.