[Python-checkins] cpython (merge 3.1 -> 3.2): merge from 3.1

senthil.kumaran python-checkins at python.org
Thu Apr 28 09:54:24 CEST 2011


http://hg.python.org/cpython/rev/492823e935b3
changeset:   69655:492823e935b3
branch:      3.2
parent:      69650:7b4c853aa07d
parent:      69654:4f9a289a1f6d
user:        Senthil Kumaran <orsenthil at gmail.com>
date:        Thu Apr 28 15:53:09 2011 +0800
summary:
  merge from 3.1

files:
  Lib/test/test_tarfile.py |  28 ++++++++++++++++++++++++++++
  1 files changed, 28 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -982,6 +982,34 @@
 
         self.assertEqual(t.name, cmp_path or path.replace(os.sep, "/"))
 
+    def test_extractall_symlinks(self):
+        # Test if extractall works properly when tarfile contains symlinks
+        tempdir = os.path.join(TEMPDIR, "testsymlinks")
+        temparchive = os.path.join(TEMPDIR, "testsymlinks.tar")
+        os.mkdir(tempdir)
+        try:
+            source_file = os.path.join(tempdir,'source')
+            target_file = os.path.join(tempdir,'symlink')
+            with open(source_file,'w') as f:
+                f.write('something\n')
+            os.symlink(source_file, target_file)
+            tar = tarfile.open(temparchive,'w')
+            tar.add(source_file)
+            tar.add(target_file)
+            tar.close()
+            # Let's extract it to the location which contains the symlink
+            tar = tarfile.open(temparchive,'r')
+            # this should not raise OSError: [Errno 17] File exists
+            try:
+                tar.extractall(path=tempdir)
+            except OSError:
+                self.fail("extractall failed with symlinked files")
+            finally:
+                tar.close()
+        finally:
+            os.unlink(temparchive)
+            shutil.rmtree(tempdir)
+
     def test_pathnames(self):
         self._test_pathname("foo")
         self._test_pathname(os.path.join("foo", ".", "bar"))

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list