now replace slashes with backslashes in symlink targets on Windows to prevent
creation of corrupted links.
(Contributed by Christoph Walcher in :gh:`57911`.)
+* :func:`~tarfile.TarFile.gettarinfo` now replaces backslashes with slashes in
+ symlink targets on Windows to conform to the tar format standard. (Contributed
+ by Daniele Nicolodi in :gh:`151669`.)
threading
type = FIFOTYPE
elif stat.S_ISLNK(stmd):
type = SYMTYPE
- linkname = os.readlink(name)
+ linkname = os.readlink(name).replace(os.sep, "/")
elif stat.S_ISCHR(stmd):
type = CHRTYPE
elif stat.S_ISBLK(stmd):
finally:
os_helper.unlink(path)
+ @os_helper.skip_unless_symlink
+ def test_symlink_target_normalization(self):
+ # Test for gh-151669.
+ path = os.path.join(TEMPDIR, "symlink")
+ target = "subdir/link/target"
+ os.symlink(target.replace("/", os.sep), path)
+ try:
+ tar = tarfile.open(tmpname, self.mode)
+ try:
+ tarinfo = tar.gettarinfo(path)
+ self.assertEqual(tarinfo.linkname, target)
+ finally:
+ tar.close()
+ finally:
+ os_helper.unlink(path)
+
def test_add_self(self):
# Test for #1257255.
dstname = os.path.abspath(tmpname)
--- /dev/null
+On Windows, when populating tar archives from filesystem content, to
+conform to the tar format standard, backslashes in symlink targets are
+be replaced by slashes.