Tuesday, March 1, 2011

Why does the tarball directory structure disappear when I use Perl's Archive::Tar?

I'm using a Perl script to modify some files inside a .tar, and the directory structure inside the resulting .tar disappears. Eliminating more and more code I've come as far as all that's required to reproduce this is

my $data_tar = Archive::Tar->new('data.tar');
$data_tar->write('modified_data.tar');

Both .tar-files have all the files, however the indication of what directories the files and subdirectories were located in are lost.

I've looked through the docs and src for Archive::Tar but I really don't understand what's going on.

I'm using perl 5.10.0 on win32, tar 1.12 and Archive::Tar 1.54. I examined the .tar-files in an editor and the data.tar contains dir/ and dir/file.txt, but in the modified_data.tar they show up as dir and file.txt so my original tar seems ok.

Anyone of you that have seen this before or have any ideas?

From stackoverflow
  • I tried your script but could not reproduce the problem (on FreeBSD using Perl 5.10).

  • C:\Temp> perl -v
    
    This is perl, v5.10.1 built for MSWin32-x86-multi-thread
    (with 2 registered patches, see perl -V for more detail)
    
    C:\Temp> perl -MArchive::Tar -e "print $Archive::Tar::VERSION"
    1.52
    

    Cannot replicate using data.tar created with:

    C:\Temp> tar --version
    tar (GNU tar) 1.21
    

    As @~quack notes, the docs state:

    Note that GNU tar earlier than version 1.14 does not cope well with the POSIX header prefix. If you use such a version, consider setting the $Archive::Tar::DO_NOT_USE_PREFIX variable to true.

    quack quixote : from the POD (regarding GNU tar versions): "Note that GNU tar earlier than version 1.14 does not cope well with the POSIX header prefix. If you use such a version, consider setting the $Archive::Tar::DO_NOT_USE_PREFIX variable to true."
    Ledhund : @~quack: I didn't really know what a posix header was so I guess I skipped past that part. This is exactly what I needed!
    R. Bemrose : @quack: I'm surprised you didn't just make that an answer, since it seems to be the problem being run into.
    Sinan Ünür : @R. Bemrose I think @~quack realized that because I originally provided the GNU tar version in my post and was nice about it.
    quack quixote : @R. Bemrose didn't know that was the answer at the time :)

0 comments:

Post a Comment