help-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-tar] Problem with tar automatically creating hard links


From: Milad Fatenejad
Subject: [Help-tar] Problem with tar automatically creating hard links
Date: Wed, 27 Mar 2013 10:28:27 -0500

Hello:
I am using tar version 1.26 on Ubuntu 12.10 64bit. I have seen that when you try to add the same file twice when creating a tar archive, tar will see that and automatically add a hard link to the archive (I assume to save space). For example:

touch a
tar cvf a.tar a a
tar tvf a.tar
-rw-rw-r-- milad/milad       0 2013-03-27 10:16 a
hrw-rw-r-- milad/milad       0 2013-03-27 10:16 a link to a

Now you can extract a from the archive without problems:
rm -f a
tar xf a

This case is fine. The problem is if you repeat the exercise and tar ./a and a:
touch a
tar cvf a.tar ./a a
tar tvf a.tar
-rw-rw-r-- milad/milad       0 2013-03-27 10:18 ./a
hrw-rw-r-- milad/milad       0 2013-03-27 10:18 a link to ./a

Now, if you try to extract the file (make sure you delete the original a first!) you get an error:
rm -f a
tar: a: Cannot hard link to `./a': No such file or directory
tar: Exiting with failure status due to previous errors

In the latter case, tar is treating a and ./a as the same file when archiving. However, upon extraction, it is treating them as different files. My friend did the same exercise using an older tar and in that case, no hard links are created and no error occurs because a and ./a are both in the archive. Is this behavior expected? I feel that this error should not occur.

Thanks
Milad

reply via email to

[Prev in Thread] Current Thread [Next in Thread]