diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2010-06-03 12:45:16 (GMT) |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2010-06-03 12:45:16 (GMT) |
commit | 1b51272b1b2565c60116119e1d4ac92602f66954 (patch) | |
tree | 6885d1e7c15ae4a1e18239622fc8a1baa11ed327 /Lib/test | |
parent | 2470ff19e620e96a39c58a2827646205024db800 (diff) | |
download | cpython-1b51272b1b2565c60116119e1d4ac92602f66954.zip cpython-1b51272b1b2565c60116119e1d4ac92602f66954.tar.gz cpython-1b51272b1b2565c60116119e1d4ac92602f66954.tar.bz2 |
Merged revisions 81667 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81667 | lars.gustaebel | 2010-06-03 14:34:14 +0200 (Thu, 03 Jun 2010) | 8 lines
Issue #8741: Fixed the TarFile.makelink() method that is responsible
for extracting symbolic and hard link entries as regular files as a
work-around on platforms that do not support filesystem links.
This stopped working reliably after a change in r74571. I also added
a few tests for this functionality.
........
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_tarfile.py | 45 | ||||
-rw-r--r-- | Lib/test/testtar.tar | bin | 289792 -> 298496 bytes |
2 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index ec6f82f..858f45b 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -133,6 +133,26 @@ class UstarReadTest(ReadTest): "read() after readline() failed") fobj.close() + # Test if symbolic and hard links are resolved by extractfile(). The + # test link members each point to a regular member whose data is + # supposed to be exported. + def _test_fileobj_link(self, lnktype, regtype): + a = self.tar.extractfile(lnktype) + b = self.tar.extractfile(regtype) + self.assertEqual(a.name, b.name) + + def test_fileobj_link1(self): + self._test_fileobj_link("ustar/lnktype", "ustar/regtype") + + def test_fileobj_link2(self): + self._test_fileobj_link("./ustar/linktest2/lnktype", "ustar/linktest1/regtype") + + def test_fileobj_symlink1(self): + self._test_fileobj_link("ustar/symtype", "ustar/regtype") + + def test_fileobj_symlink2(self): + self._test_fileobj_link("./ustar/linktest2/symtype", "ustar/linktest1/regtype") + class CommonReadTest(ReadTest): @@ -1378,6 +1398,29 @@ class ContextManagerTest(unittest.TestCase): fobj.close() +class LinkEmulationTest(ReadTest): + + # Test for issue #8741 regression. On platforms that do not support + # symbolic or hard links tarfile tries to extract these types of members as + # the regular files they point to. + def _test_link_extraction(self, name): + self.tar.extract(name, TEMPDIR) + data = open(os.path.join(TEMPDIR, name), "rb").read() + self.assertEqual(md5sum(data), md5_regtype) + + def test_hardlink_extraction1(self): + self._test_link_extraction("ustar/lnktype") + + def test_hardlink_extraction2(self): + self._test_link_extraction("./ustar/linktest2/lnktype") + + def test_symlink_extraction1(self): + self._test_link_extraction("ustar/symtype") + + def test_symlink_extraction2(self): + self._test_link_extraction("./ustar/linktest2/symtype") + + class GzipMiscReadTest(MiscReadTest): tarname = gzipname mode = "r:gz" @@ -1463,6 +1506,8 @@ def test_main(): if hasattr(os, "link"): tests.append(HardlinkTest) + else: + tests.append(LinkEmulationTest) fobj = open(tarname, "rb") data = fobj.read() diff --git a/Lib/test/testtar.tar b/Lib/test/testtar.tar Binary files differindex c3022ed..dc1942c 100644 --- a/Lib/test/testtar.tar +++ b/Lib/test/testtar.tar |