]> granicus.if.org Git - python/commitdiff
Merged revisions 72893 via svnmerge from
authorMartin v. Löwis <martin@v.loewis.de>
Sun, 24 May 2009 19:47:22 +0000 (19:47 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Sun, 24 May 2009 19:47:22 +0000 (19:47 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r72893 | martin.v.loewis | 2009-05-24 21:30:52 +0200 (So, 24 Mai 2009) | 3 lines

  Issue #6050: Don't fail extracting a directory from a zipfile if
  the directory already exists.
........

Lib/test/test_zipfile.py
Lib/zipfile.py
Misc/NEWS

index 3b04ce2ecfa527b0f1a89c6435cf6210fc0f097b..4b6d82540ff09505250a631d7398ac13fb91b575 100644 (file)
@@ -1012,6 +1012,11 @@ class TestWithDirectory(unittest.TestCase):
         self.assertTrue(os.path.isdir(os.path.join(TESTFN2, "a", "b")))
         self.assertTrue(os.path.exists(os.path.join(TESTFN2, "a", "b", "c")))
 
+    def test_bug_6050(self):
+        # Extraction should succeed if directories already exist
+        os.mkdir(os.path.join(TESTFN2, "a"))
+        self.testExtractDir()
+
     def testStoreDir(self):
         os.mkdir(os.path.join(TESTFN2, "x"))
         zipf = zipfile.ZipFile(TESTFN, "w")
index dab595bb7a487833ee1321b38f9dc609c5f493c0..5f2efb9b3cdf0cd0e5da70cbfa8595a3fe837d71 100644 (file)
@@ -978,7 +978,8 @@ class ZipFile:
             os.makedirs(upperdirs)
 
         if member.filename[-1] == '/':
-            os.mkdir(targetpath)
+            if not os.path.isdir(targetpath):
+                os.mkdir(targetpath)
             return targetpath
 
         source = self.open(member, pwd=pwd)
index 76f877308354dcbe97658b1645b282840952bb6b..ca3077a2ff53a0042f5ebcaee6f384fa757182f0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -32,6 +32,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #6050: Don't fail extracting a directory from a zipfile if
+  the directory already exists.
+
 - Issue #1309352: fcntl now converts its third arguments to a C `long` rather
   than an int, which makes some operations possible under 64-bit Linux (e.g.
   DN_MULTISHOT with F_NOTIFY).