mirror of
https://github.com/python/cpython.git
synced 2025-12-05 00:52:25 +00:00
SF #857297 and 916874, improve handling of hard links when extracting
This commit is contained in:
parent
0662f8a5ea
commit
a4f651a2ae
3 changed files with 30 additions and 1 deletions
|
|
@ -1294,6 +1294,10 @@ class TarFile(object):
|
||||||
else:
|
else:
|
||||||
tarinfo = self.getmember(member)
|
tarinfo = self.getmember(member)
|
||||||
|
|
||||||
|
# Prepare the link target for makelink().
|
||||||
|
if tarinfo.islnk():
|
||||||
|
tarinfo._link_target = os.path.join(path, tarinfo.linkname)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._extract_member(tarinfo, os.path.join(path, tarinfo.name))
|
self._extract_member(tarinfo, os.path.join(path, tarinfo.name))
|
||||||
except EnvironmentError, e:
|
except EnvironmentError, e:
|
||||||
|
|
@ -1466,7 +1470,8 @@ class TarFile(object):
|
||||||
if tarinfo.issym():
|
if tarinfo.issym():
|
||||||
os.symlink(linkpath, targetpath)
|
os.symlink(linkpath, targetpath)
|
||||||
else:
|
else:
|
||||||
os.link(linkpath, targetpath)
|
# See extract().
|
||||||
|
os.link(tarinfo._link_target, targetpath)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
if tarinfo.issym():
|
if tarinfo.issym():
|
||||||
linkpath = os.path.join(os.path.dirname(tarinfo.name),
|
linkpath = os.path.join(os.path.dirname(tarinfo.name),
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,24 @@ class WriteGNULongTest(unittest.TestCase):
|
||||||
self._test(("longnam/" * 127) + "longname_",
|
self._test(("longnam/" * 127) + "longname_",
|
||||||
("longlnk/" * 127) + "longlink_")
|
("longlnk/" * 127) + "longlink_")
|
||||||
|
|
||||||
|
class ExtractHardlinkTest(BaseTest):
|
||||||
|
|
||||||
|
def test_hardlink(self):
|
||||||
|
"""Test hardlink extraction (bug #857297)
|
||||||
|
"""
|
||||||
|
# Prevent errors from being caught
|
||||||
|
self.tar.errorlevel = 1
|
||||||
|
|
||||||
|
self.tar.extract("0-REGTYPE", dirname())
|
||||||
|
try:
|
||||||
|
# Extract 1-LNKTYPE which is a hardlink to 0-REGTYPE
|
||||||
|
self.tar.extract("1-LNKTYPE", dirname())
|
||||||
|
except EnvironmentError, e:
|
||||||
|
import errno
|
||||||
|
if e.errno == errno.ENOENT:
|
||||||
|
self.fail("hardlink not extracted properly")
|
||||||
|
|
||||||
|
|
||||||
# Gzip TestCases
|
# Gzip TestCases
|
||||||
class ReadTestGzip(ReadTest):
|
class ReadTestGzip(ReadTest):
|
||||||
comp = "gz"
|
comp = "gz"
|
||||||
|
|
@ -337,6 +355,9 @@ def test_main():
|
||||||
WriteGNULongTest,
|
WriteGNULongTest,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if hasattr(os, "link"):
|
||||||
|
tests.append(ExtractHardlinkTest)
|
||||||
|
|
||||||
if gzip:
|
if gzip:
|
||||||
tests.extend([
|
tests.extend([
|
||||||
ReadTestGzip, ReadStreamTestGzip,
|
ReadTestGzip, ReadStreamTestGzip,
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,9 @@ Extension modules
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Bug #857297/Patch #916874. Fix an error when extracting a hard link
|
||||||
|
from a tarfile.
|
||||||
|
|
||||||
- Patch #846659. Fix an error in tarfile.py when using
|
- Patch #846659. Fix an error in tarfile.py when using
|
||||||
GNU longname/longlink creation.
|
GNU longname/longlink creation.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue