Issue 1331635: tarfile.py: fix for 1330039 (original) (raw)

The attached patch fixes bug #1330039. The patch includes a testcase.

A file is added to an archive as a hardlink if a file with the same inode number (and device number) was added before without futher checks. This leads to the undesired behaviour described in #1330039, i.e. if two throwaway temporary files are assigned the same inode number by the filesystem, the second one will be added as a hardlink to the first, which means that the content will be lost.

The patched code checks if the file's st_nlink is greater 1. So only for files that actually have several links pointing to them hardlinks will be created, which is what GNU tar does.