A feature-rich command-line audio/video downloader
[utils] Fix race condition in `make_dir` (#6089)
Alex Ionescub25d6cb96337
diff --git a/yt_dlp/cache.py b/yt_dlp/cache.pyindex 7be91eae5d..f8344fe77a 100644--- a/yt_dlp/cache.py+++ b/yt_dlp/cache.py@@ -39,11 +39,7 @@ class Cache:fn = self._get_cache_fn(section, key, dtype)try:- try:- os.makedirs(os.path.dirname(fn))- except OSError as ose:- if ose.errno != errno.EEXIST:- raise+ os.makedirs(os.path.dirname(fn), exist_ok=True)self._ydl.write_debug(f'Saving {section}.{key} to cache')write_json_file({'yt-dlp_version': __version__, 'data': data}, fn)except Exception:diff --git a/yt_dlp/utils.py b/yt_dlp/utils.pyindex 2d9e61c5bb..736468aefa 100644--- a/yt_dlp/utils.py+++ b/yt_dlp/utils.py@@ -5370,8 +5370,8 @@ def random_uuidv4():def make_dir(path, to_screen=None):try:dn = os.path.dirname(path)- if dn and not os.path.exists(dn):- os.makedirs(dn)+ if dn:+ os.makedirs(dn, exist_ok=True)return Trueexcept OSError as err:if callable(to_screen) is not None: