Skip to content

Commit 5e81a45

Browse files
committed
gh-112998: zipfile: fix extractall makedirs race condition
1 parent 3251ba8 commit 5e81a45

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Lib/zipfile/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,11 +1781,14 @@ def _extract_member(self, member, targetpath, pwd):
17811781
# Create all upper directories if necessary.
17821782
upperdirs = os.path.dirname(targetpath)
17831783
if upperdirs and not os.path.exists(upperdirs):
1784-
os.makedirs(upperdirs)
1784+
os.makedirs(upperdirs, exist_ok=True)
17851785

17861786
if member.is_dir():
17871787
if not os.path.isdir(targetpath):
1788-
os.mkdir(targetpath)
1788+
try:
1789+
os.mkdir(targetpath)
1790+
except FileExistsError:
1791+
pass
17891792
return targetpath
17901793

17911794
with self.open(member, pwd=pwd) as source, \
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``zipfile`` - Avoid race condition creating parent directories when
2+
extracting concurrently.

0 commit comments

Comments
 (0)