8

I got a tarball (let's say t.tar.gz) that contains the following files

./a/a.txt
./b/b.txt 

where ./b/b.txt is a hard link to ./a/a.txt.

I want to unpack the tarball on a network file system (AFS) that only supports hard links in the same directory (see here). Therefore, just unpacking it via tar -xzf t.tar.gz raises an error that the hard link ./b/b.txt cannot be created.

So far, my solution to the problem was to unpack ./t.tar.gz on a file system that supports ordinary hard links. Then pack it again with the option --hard-dereference as the GNU tar manual proposes. And lastly, unpack that new tarball into the AFS.

As this is unsatisfactory for me, I'm asking if there is an easier way to get the content of the archive unpacked directly to it's final destination? Such as an equivalent option to --hard-dereference for unpacking instead of archiving?

Denis
  • 191
  • 1
  • 5
  • it [appears not](https://www.gnu.org/software/tar/manual/tar.html#SEC141), to me – Jeff Schaller Feb 22 '16 at 13:34
  • 4
    Given JeffSchaller's comment, may I suggest "[How do I dereference links when extracting from a tar file?](http://unix.stackexchange.com/questions/22998/how-do-i-dereference-links-when-extracting-from-a-tar-file)"? This `mountavfs` approach appears quite simple. – John WH Smith Feb 22 '16 at 21:19
  • 1
    @JohnWHSmith I don't think that makes the questions duplicates. Many solutions will work for both, to be sure, but there could be solutions for hard links that don't work for symbolic links or vice versa. – Gilles 'SO- stop being evil' Feb 22 '16 at 23:25

1 Answers1

2

Mount the archive as a directory, for example with AVFS, then use your favorite file copying tool.

mountavfs
cp -a --no-preserve=links ~/.avfs/path/to/t.tar.gz\# target-directory/

or

mountavfs
rsync -a ~/.avfs/path/to/t.tar.gz\#/ target-directory/
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
  • Thanks for the introduction to mountavfs. This seems to be the best option for me right now. – Denis Mar 01 '16 at 08:39