tlhackque has asked for the wisdom of the Perl Monks concerning the following question:

I don't think it's me, but thought I'd see what other eyes see...

Using Archive::Tar, if I create a tar file of a symlink with FOLLOW_SYMLINK = 1, the write fails. Here's the 1-line reproducer. Perl 5.12.4, fedora 15

# touch foo # ln -s foo bar # perl -MArchive::Tar -e'$Archive::Tar::FOLLOW_SYMLINK = 1; my $t = Ar +chive::Tar->new; $t->add_files("bar"); $t->write( "baz.tgz", COMPRESS +_GZIP );print $t->error(1); print $Archive::Tar::VERSION' Could not write data for: bar at -e line 1 Could not write data for: bar at /usr/share/perl5/Archive/Tar.pm line +1293 Archive::Tar::write('Archive::Tar=HASH(0x9dcf90)', 'baz.tgz', +9) called at -e line 1 1.78
The same command adding "foo" instead of bar works. Hard to imagine something so simple being broken - but I can't see what I'm doing wrong!

Thanks for any help.

This communication may not represent my employer's views, if any, on the matters discussed.

Replies are listed 'Best First'.
Re: Archive::Tar fails to dereference and save symlinks?
by Khen1950fx (Canon) on Sep 16, 2011 at 02:54 UTC
    It's not broken:). You're trying to print the error method, but it doesn't like that. This worked for me:
    #!/usr/bin/perl -slw use strict; use Archive::Tar; use Data::Dumper::Concise; $Archive::Tar::FOLLOW_SYMLINK = 1; print $Archive::Tar::VERSION; my $t = Archive::Tar->new; $t->add_files('/root/Desktop/bar'); $t->write( 'baz.tgz', COMPRESS_GZIP ); $t->error(1); print "Done";
      Thanks, but there's something different about our environments.

      I downloaded your code. Commented out the "Data::Dumper::Concise" since you don't use it and it isn't installed on my system. Changed output file name (don't have a Desktop on this system).

      Still get error. Yes, the .tgz gets created (didn't notice this before).

      More interesting, if instead of a 0 byte file (Did you duplicate that?), I do echo "abcd">foo - the error goes away.

      BUT: the .tgz is corrupt. Sometimes.

      #!/usr/bin/perl -slw use strict; use Archive::Tar; #use Data::Dumper::Concise; $Archive::Tar::FOLLOW_SYMLINK = 1; print $Archive::Tar::VERSION; my $t = Archive::Tar->new; $t->add_files('bar'); $t->write( 'baz.tgz', COMPRESS_GZIP ); $t->error(1); print "Done"; ls -l foo bar baz.tgz ls: cannot access baz.tgz: No such file or directory lrwxrwxrwx. 1 root root 3 Sep 15 19:35 bar -> foo -rw-r--r--. 1 root root 0 Sep 15 23:19 foo # perl z.tmp 1.78 Could not write data for: bar at z.tmp line 12 Done # echo "abcd" >foo # ls -l foo bar baz.tgz lrwxrwxrwx. 1 root root 3 Sep 15 19:35 bar -> foo -rw-r--r--. 1 root root 97 Sep 15 23:21 baz.tgz -rw-r--r--. 1 root root 5 Sep 15 23:20 foo # rm baz.tgz # perl z.tmp 1.78 Done ]# ls -l foo bar baz.tgz lrwxrwxrwx. 1 root root 3 Sep 15 19:35 bar -> foo -rw-r--r--. 1 root root 97 Sep 15 23:25 baz.tgz -rw-r--r--. 1 root root 5 Sep 15 23:20 foo And sometimes, I get # tar -tzvf baz.tgz -rw-r--r-- root/root 0 2011-09-15 19:35 bar tar: Skipping to next header tar: Exiting with failure status due to previous errors
      I'm not hallucinating. (This is a reduced test case from larger program; it normally does more work.)