diff options
Diffstat (limited to 'django/core/files/storage.py')
| -rw-r--r-- | django/core/files/storage.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/django/core/files/storage.py b/django/core/files/storage.py index fa98bb198a..30788d6d75 100644 --- a/django/core/files/storage.py +++ b/django/core/files/storage.py @@ -1,5 +1,4 @@ import os -from contextlib import suppress from datetime import datetime from urllib.parse import urljoin @@ -224,10 +223,7 @@ class FileSystemStorage(Storage): # Create any intermediate directories that do not exist. directory = os.path.dirname(full_path) if not os.path.exists(directory): - # There's a race between os.path.exists() and os.makedirs(). - # If os.makedirs() fails with FileNotFoundError, the directory - # was created concurrently. - with suppress(FileNotFoundError): + try: if self.directory_permissions_mode is not None: # os.makedirs applies the global umask, so we reset it, # for consistency with file_permissions_mode behavior. @@ -238,6 +234,11 @@ class FileSystemStorage(Storage): os.umask(old_umask) else: os.makedirs(directory) + except FileNotFoundError: + # There's a race between os.path.exists() and os.makedirs(). + # If os.makedirs() fails with FileNotFoundError, the directory + # was created concurrently. + pass if not os.path.isdir(directory): raise IOError("%s exists and is not a directory." % directory) @@ -293,13 +294,15 @@ class FileSystemStorage(Storage): assert name, "The name argument is not allowed to be empty." name = self.path(name) # If the file or directory exists, delete it from the filesystem. - # FileNotFoundError is raised if the file or directory was removed - # concurrently. - with suppress(FileNotFoundError): + try: if os.path.isdir(name): os.rmdir(name) else: os.remove(name) + except FileNotFoundError: + # FileNotFoundError is raised if the file or directory was removed + # concurrently. + pass def exists(self, name): return os.path.exists(self.path(name)) |
