diff options
author | Christoph Reiter <reiter.christoph@gmail.com> | 2019-04-17 20:33:12 +0200 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2019-04-17 20:33:12 +0200 |
commit | 2e9554ec13e362dc1d289e2f4ba4ad79e1c1ef1a (patch) | |
tree | be4ba286d7848a98b5d032b69e6315ef50362e5b /giscanner | |
parent | 7f809c314ec3283d8f85c4a3557ccca42f118c63 (diff) | |
download | gobject-introspection-2e9554ec13e362dc1d289e2f4ba4ad79e1c1ef1a.tar.gz |
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.
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/cachestore.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/giscanner/cachestore.py b/giscanner/cachestore.py index e98b52f1..baaaf1ed 100644 --- a/giscanner/cachestore.py +++ b/giscanner/cachestore.py @@ -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-') |