From 532b68dd07c2f9b9180d749735f4d8c0b9c5f239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Mon, 18 Sep 2023 00:32:36 +0200 Subject: [PATCH] fix: Avoid exception when attempting to move a capture --- bin/background_indexer.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/background_indexer.py b/bin/background_indexer.py index c37c8e57..5238049b 100755 --- a/bin/background_indexer.py +++ b/bin/background_indexer.py @@ -67,7 +67,10 @@ class BackgroundIndexer(AbstractManager): if cached_path.exists(): # Both paths exist, move the one that isn't in lookup_dirs self.logger.critical(f'Duplicate UUID for {uuid} in {cached_path} and {uuid_path.parent}, discarding the latest') - shutil.move(str(uuid_path.parent), str(self.discarded_captures_dir / uuid_path.parent.name)) + try: + shutil.move(str(uuid_path.parent), str(self.discarded_captures_dir / uuid_path.parent.name)) + except FileNotFoundError as e: + self.logger.warning(f'Unable to move capture: {e}') continue else: # The path in lookup_dirs for that UUID doesn't exists, just update it. @@ -89,8 +92,12 @@ class BackgroundIndexer(AbstractManager): except Exception: self.logger.exception(f'Unable to build pickle for {uuid}: {uuid_path.parent.name}') # The capture is not working, moving it away. - self.lookyloo.redis.hdel('lookup_dirs', uuid) - shutil.move(str(uuid_path.parent), str(self.discarded_captures_dir / uuid_path.parent.name)) + try: + shutil.move(str(uuid_path.parent), str(self.discarded_captures_dir / uuid_path.parent.name)) + self.lookyloo.redis.hdel('lookup_dirs', uuid) + except FileNotFoundError as e: + self.logger.warning(f'Unable to move capture: {e}') + continue if max_captures <= 0: self.logger.info('Too many captures in the backlog, start from the beginning.') return False