From daca988f3feb1b0a2c91fb67e93d2804f36ce233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 26 Nov 2021 12:36:35 -0500 Subject: [PATCH] chg: better handling of broken indexes in archiver --- bin/archiver.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/archiver.py b/bin/archiver.py index 01d320a..69dddfa 100755 --- a/bin/archiver.py +++ b/bin/archiver.py @@ -36,18 +36,20 @@ class Archiver(AbstractManager): self._load_indexes() def _update_index(self, root_dir: Path) -> None: - current_index: Dict[str, str] + current_index: Dict[str, str] = {} index_file = root_dir / 'index' if index_file.exists(): # Skip index if the directory has been archived. existing_captures = index_file.parent.iterdir() - with index_file.open('r') as _f: - current_index = {uuid: dirname for uuid, dirname in csv.reader(_f) if (index_file.parent / dirname) in existing_captures} + try: + with index_file.open('r') as _f: + current_index = {uuid: dirname for uuid, dirname in csv.reader(_f) if (index_file.parent / dirname) in existing_captures} + except Exception: + # the index file is broken, it will be recreated. + pass if not current_index: index_file.unlink() - else: - current_index = {} for uuid_file in root_dir.glob('*/uuid'): if uuid_file.parent.name in current_index.values():