fix: unlink indexes pointing to unknown directories

pull/254/head
Raphaël Vinot 2021-08-30 14:45:44 +02:00
parent 4c4b01547a
commit 2e5a5f3aff
1 changed files with 10 additions and 4 deletions

View File

@ -116,14 +116,20 @@ class Archiver(AbstractManager):
# Initialize archives
for index in get_captures_dir().glob('**/index'):
with index.open('r') as _f:
recent_uuids: Dict[str, str] = {uuid: str(index.parent / dirname) for uuid, dirname in csv.reader(_f)}
self.redis.hmset('lookup_dirs', recent_uuids) # type: ignore
recent_uuids: Dict[str, str] = {uuid: str(index.parent / dirname) for uuid, dirname in csv.reader(_f) if (index.parent / dirname).exists()}
if recent_uuids:
self.redis.hmset('lookup_dirs', recent_uuids) # type: ignore
else:
index.unlink()
# Initialize archives
for index in self.archived_captures_dir.glob('**/index'):
with index.open('r') as _f:
archived_uuids: Dict[str, str] = {uuid: str(index.parent / dirname) for uuid, dirname in csv.reader(_f)}
self.redis.hmset('lookup_dirs_archived', archived_uuids) # type: ignore
archived_uuids: Dict[str, str] = {uuid: str(index.parent / dirname) for uuid, dirname in csv.reader(_f) if (index.parent / dirname).exists()}
if archived_uuids:
self.redis.hmset('lookup_dirs_archived', archived_uuids) # type: ignore
else:
index.unlink()
def main():