mirror of
https://github.com/python/cpython.git
synced 2025-12-08 10:21:13 +00:00
Issue #16645: Fix hardlink extracting test for tarfile.
This commit is contained in:
parent
bac04e51ca
commit
88339c44f8
1 changed files with 6 additions and 16 deletions
|
|
@ -328,31 +328,21 @@ class MiscReadTest(CommonReadTest):
|
||||||
@support.skip_unless_symlink
|
@support.skip_unless_symlink
|
||||||
def test_extract_hardlink(self):
|
def test_extract_hardlink(self):
|
||||||
# Test hardlink extraction (e.g. bug #857297).
|
# Test hardlink extraction (e.g. bug #857297).
|
||||||
tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1")
|
with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar:
|
||||||
|
|
||||||
try:
|
|
||||||
tar.extract("ustar/regtype", TEMPDIR)
|
tar.extract("ustar/regtype", TEMPDIR)
|
||||||
try:
|
self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/regtype"))
|
||||||
tar.extract("ustar/lnktype", TEMPDIR)
|
|
||||||
except EnvironmentError as e:
|
|
||||||
if e.errno == errno.ENOENT:
|
|
||||||
self.fail("hardlink not extracted properly")
|
|
||||||
|
|
||||||
|
tar.extract("ustar/lnktype", TEMPDIR)
|
||||||
|
self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/lnktype"))
|
||||||
with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f:
|
with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
self.assertEqual(md5sum(data), md5_regtype)
|
self.assertEqual(md5sum(data), md5_regtype)
|
||||||
|
|
||||||
try:
|
|
||||||
tar.extract("ustar/symtype", TEMPDIR)
|
tar.extract("ustar/symtype", TEMPDIR)
|
||||||
except EnvironmentError as e:
|
self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/symtype"))
|
||||||
if e.errno == errno.ENOENT:
|
|
||||||
self.fail("symlink not extracted properly")
|
|
||||||
|
|
||||||
with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f:
|
with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f:
|
||||||
data = f.read()
|
data = f.read()
|
||||||
self.assertEqual(md5sum(data), md5_regtype)
|
self.assertEqual(md5sum(data), md5_regtype)
|
||||||
finally:
|
|
||||||
tar.close()
|
|
||||||
|
|
||||||
def test_extractall(self):
|
def test_extractall(self):
|
||||||
# Test if extractall() correctly restores directory permissions
|
# Test if extractall() correctly restores directory permissions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue