[utils] Fix race condition in make_dir (#6089)

Authored by: aionescu
This commit is contained in:
Alex Ionescu 2023-02-17 04:29:32 +01:00 committed by GitHub
parent 3616300155
commit b25d6cb963
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 7 deletions

View file

@ -39,11 +39,7 @@ class Cache:
fn = self._get_cache_fn(section, key, dtype) fn = self._get_cache_fn(section, key, dtype)
try: try:
try: os.makedirs(os.path.dirname(fn), exist_ok=True)
os.makedirs(os.path.dirname(fn))
except OSError as ose:
if ose.errno != errno.EEXIST:
raise
self._ydl.write_debug(f'Saving {section}.{key} to cache') self._ydl.write_debug(f'Saving {section}.{key} to cache')
write_json_file({'yt-dlp_version': __version__, 'data': data}, fn) write_json_file({'yt-dlp_version': __version__, 'data': data}, fn)
except Exception: except Exception:

View file

@ -5370,8 +5370,8 @@ def random_uuidv4():
def make_dir(path, to_screen=None): def make_dir(path, to_screen=None):
try: try:
dn = os.path.dirname(path) dn = os.path.dirname(path)
if dn and not os.path.exists(dn): if dn:
os.makedirs(dn) os.makedirs(dn, exist_ok=True)
return True return True
except OSError as err: except OSError as err:
if callable(to_screen) is not None: if callable(to_screen) is not None: