diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index 8005b4b34ccf76..b690cd39b6cf7c 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -1802,11 +1802,14 @@ def _extract_member(self, member, targetpath, pwd): # Create all upper directories if necessary. upperdirs = os.path.dirname(targetpath) if upperdirs and not os.path.exists(upperdirs): - os.makedirs(upperdirs) + os.makedirs(upperdirs, exist_ok=True) if member.is_dir(): if not os.path.isdir(targetpath): - os.mkdir(targetpath) + try: + os.mkdir(targetpath) + except FileExistsError: + pass return targetpath with self.open(member, pwd=pwd) as source, \ diff --git a/Misc/NEWS.d/next/Library/2023-12-12-10-25-46.gh-issue-112998.F2QyD0.rst b/Misc/NEWS.d/next/Library/2023-12-12-10-25-46.gh-issue-112998.F2QyD0.rst new file mode 100644 index 00000000000000..c0c79a41a84a7e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-12-12-10-25-46.gh-issue-112998.F2QyD0.rst @@ -0,0 +1,2 @@ +``zipfile`` - Avoid race condition creating parent directories when +extracting concurrently.