Skip to content

Commit 5569c80

Browse files
authored
Fixed #179: Catch potential FileNotFoundError
When multiple processes share the same file cache, a file can potentially be deleted between the check for existence (`if not os.path.exists(name)`) and the actual read operation.
1 parent bc43a32 commit 5569c80

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cachecontrol/caches/file_cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ def _fn(self, name):
9595

9696
def get(self, key):
9797
name = self._fn(key)
98-
if not os.path.exists(name):
98+
try:
99+
with open(name, 'rb') as fh:
100+
return fh.read()
101+
except FileNotFoundError:
99102
return None
100103

101-
with open(name, 'rb') as fh:
102-
return fh.read()
103-
104104
def set(self, key, value):
105105
name = self._fn(key)
106106

0 commit comments

Comments
 (0)