diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2016-05-26 08:36:00 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-05-31 12:03:27 -0400 |
| commit | 359be1c8702ede41e7fe823ed13350795ba96a61 (patch) | |
| tree | 064509b4b6e7537d24890b0049ef9ca4e171387a /tests/staticfiles_tests | |
| parent | e3877c53edb33271b0f31d20e60a924848692026 (diff) | |
Fixed #26691 -- Removed checking for a file's existence before deleting.
File operations always raise a ENOENT error when a file doesn't exist.
Checking the file exists before the operation adds a race condition
condition where the file could be removed between operations. As the
operation already raises an error on a missing file, avoid this race and
avoid checking the file exists twice. Instead only check a file exists
by catching the ENOENT error.
Diffstat (limited to 'tests/staticfiles_tests')
| -rw-r--r-- | tests/staticfiles_tests/storage.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/tests/staticfiles_tests/storage.py b/tests/staticfiles_tests/storage.py index 8c474591f3..cf648f06f2 100644 --- a/tests/staticfiles_tests/storage.py +++ b/tests/staticfiles_tests/storage.py @@ -48,12 +48,11 @@ class PathNotImplementedStorage(storage.Storage): def delete(self, name): name = self._path(name) - if os.path.exists(name): - try: - os.remove(name) - except OSError as e: - if e.errno != errno.ENOENT: - raise + try: + os.remove(name) + except OSError as e: + if e.errno != errno.ENOENT: + raise def path(self, name): raise NotImplementedError |
