☔ Remove stale entries from metadata

If a file no longer exists on disk for whatever reason it also doesn't
need to be kept in metadata.json.

See also #3057

Cherry-picked from 15d3b2ca
This commit is contained in:
Gina Häußge committed 2019-03-05 16:20:13 +01:00
1 parent 3e16f0901a
commit 7d0bd6a339
1 file changed
+9 -1
+9 -1
View File
@@ -1530,7 +1530,15 @@ class LocalFileStorage(StorageInterface):
self._logger.exception("Error while reading .metadata.json from {path}".format(**locals()))
else:
if isinstance(metadata, dict):
self._metadata_cache[path] = deepcopy(metadata)
old_size = len(metadata)
metadata = { k: v for k, v in metadata.items() if os.path.exists(os.path.join(path, k)) }
new_size = len(metadata)
if new_size != old_size:
self._logger.info("Deleted {} stale entries from metadata for path {}".format(old_size - new_size,
path))
self._save_metadata(path, metadata)
else:
self._metadata_cache[path] = deepcopy(metadata)
return metadata
return dict()