From: Senthil Kumaran Date: Fri, 29 Apr 2011 22:09:51 +0000 (+0800) Subject: merge from 3.1 X-Git-Tag: v3.2.1b1~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=be5dbebeaa012d383c0d9f4da39b68c4b04b5775;p=thirdparty%2FPython%2Fcpython.git merge from 3.1 --- be5dbebeaa012d383c0d9f4da39b68c4b04b5775 diff --cc Lib/test/test_tarfile.py index f363f701cb19,6c7db9535f50..8036c5cda138 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@@ -327,31 -230,25 +327,30 @@@ class MiscReadTest(CommonReadTest) # Test hardlink extraction (e.g. bug #857297). tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") - tar.extract("ustar/regtype", TEMPDIR) try: - tar.extract("ustar/lnktype", TEMPDIR) - except EnvironmentError as e: - if e.errno == errno.ENOENT: - self.fail("hardlink not extracted properly") - - data = open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb").read() - self.assertEqual(md5sum(data), md5_regtype) + tar.extract("ustar/regtype", TEMPDIR) + try: + tar.extract("ustar/lnktype", TEMPDIR) + except EnvironmentError as e: + if e.errno == errno.ENOENT: + self.fail("hardlink not extracted properly") - try: - tar.extract("ustar/symtype", TEMPDIR) - except EnvironmentError as e: - if e.errno == errno.ENOENT: - self.fail("symlink not extracted properly") + with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f: + data = f.read() + self.assertEqual(md5sum(data), md5_regtype) - data = open(os.path.join(TEMPDIR, "ustar/symtype"), "rb").read() - self.assertEqual(md5sum(data), md5_regtype) + try: + tar.extract("ustar/symtype", TEMPDIR) + except EnvironmentError as e: + if e.errno == errno.ENOENT: + self.fail("symlink not extracted properly") + + with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f: + data = f.read() + self.assertEqual(md5sum(data), md5_regtype) + finally: + tar.close() - @support.skip_unless_symlink def test_extractall(self): # Test if extractall() correctly restores directory permissions # and times (see issue1735). @@@ -951,38 -678,7 +950,40 @@@ class WriteTest(WriteTestBase) finally: shutil.rmtree(tempdir) - @unittest.skipUnless(hasattr(os,'symlink'), "needs os.symlink") + # Guarantee that stored pathnames are not modified. Don't + # remove ./ or ../ or double slashes. Still make absolute + # pathnames relative. + # For details see bug #6054. + def _test_pathname(self, path, cmp_path=None, dir=False): + # Create a tarfile with an empty member named path + # and compare the stored name with the original. + foo = os.path.join(TEMPDIR, "foo") + if not dir: + open(foo, "w").close() + else: + os.mkdir(foo) + + tar = tarfile.open(tmpname, self.mode) + try: + tar.add(foo, arcname=path) + finally: + tar.close() + + tar = tarfile.open(tmpname, "r") + try: + t = tar.next() + finally: + tar.close() + + if not dir: + os.remove(foo) + else: + os.rmdir(foo) + + self.assertEqual(t.name, cmp_path or path.replace(os.sep, "/")) + ++ ++ @support.skip_unless_symlink def test_extractall_symlinks(self): # Test if extractall works properly when tarfile contains symlinks tempdir = os.path.join(TEMPDIR, "testsymlinks")