Commit 2e9554ec authored by Christoph Reiter's avatar Christoph Reiter 🐍

cachestore: handle cache getting deleted while loading it. Fixes #278

In the unlucky event where the cache gets deleted after the os.path.exists()
check but before we get its mtime things would error out.

Instead of using os.path.exists() handle the exceptions of the operations
which we expect to possibly fail.
parent 7f809c31
Pipeline #76695 passed with stages
in 5 minutes and 51 seconds
......@@ -106,8 +106,12 @@ class CacheStore(object):
return os.path.join(self._directory, hexdigest)
def _cache_is_valid(self, store_filename, filename):
return (os.stat(store_filename).st_mtime >=
os.stat(filename).st_mtime)
try:
store_mtime = os.stat(store_filename).st_mtime
except FileNotFoundError:
return False
return store_mtime >= os.stat(filename).st_mtime
def _remove_filename(self, filename):
try:
......@@ -130,7 +134,7 @@ class CacheStore(object):
if store_filename is None:
return
if (os.path.exists(store_filename) and self._cache_is_valid(store_filename, filename)):
if self._cache_is_valid(store_filename, filename):
return None
tmp_fd, tmp_filename = tempfile.mkstemp(prefix='g-ir-scanner-cache-')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment