diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 21fc703d4e72..1fed79acae1c 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -994,6 +994,11 @@ def testExtractDir(self): 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") diff --git a/Lib/zipfile.py b/Lib/zipfile.py index aa88563e5f1c..a50a45833614 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -959,7 +959,8 @@ def _extract_member(self, member, targetpath, pwd): 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) diff --git a/Misc/NEWS b/Misc/NEWS index 6264e58fa309..1c03d701dfec 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -50,6 +50,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).