diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-02-11 10:38:07 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-11 10:38:07 (GMT) |
commit | 5d2794a16bc1639e6053300c08a78d60526aadf2 (patch) | |
tree | 7530ef4d000872d6cfad32a7b90d831e785143f4 /Lib/zipfile | |
parent | bf75f1b147b8cc4c5506df7c4bb30b9950ceda1a (diff) | |
download | cpython-5d2794a16bc1639e6053300c08a78d60526aadf2.zip cpython-5d2794a16bc1639e6053300c08a78d60526aadf2.tar.gz cpython-5d2794a16bc1639e6053300c08a78d60526aadf2.tar.bz2 |
gh-67837, gh-112998: Fix dirs creation in concurrent extraction (GH-115082)
Avoid race conditions in the creation of directories during concurrent
extraction in tarfile and zipfile.
Co-authored-by: Samantha Hughes <shughes-uk@users.noreply.github.com>
Co-authored-by: Peder Bergebakken Sundt <pbsds@hotmail.com>
Diffstat (limited to 'Lib/zipfile')
-rw-r--r-- | Lib/zipfile/__init__.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index 8005b4b..cc08f60 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -1802,11 +1802,15 @@ class ZipFile: # 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: + if not os.path.isdir(targetpath): + raise return targetpath with self.open(member, pwd=pwd) as source, \ |