From e818aa2a8b789c4137ef26fc572d83ce3e012b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 23 Apr 2024 14:57:45 +0300 Subject: [PATCH] chg: remove empty capture dirs --- lookyloo/capturecache.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lookyloo/capturecache.py b/lookyloo/capturecache.py index eca66219..44f33736 100644 --- a/lookyloo/capturecache.py +++ b/lookyloo/capturecache.py @@ -385,8 +385,15 @@ class CapturesIndex(Mapping): # type: ignore[type-arg] '''Populate the redis cache for a capture. Mostly used on the index page. NOTE: Doesn't require the pickle.''' capture_dir = Path(capture_dir_str) - with (capture_dir / 'uuid').open() as f: - uuid = f.read().strip() + try: + with (capture_dir / 'uuid').open() as f: + uuid = f.read().strip() + except FileNotFoundError: + if not os.listdir(capture_dir_str): + # The directory is empty, removing it + os.rmdir(capture_dir_str) + raise MissingCaptureDirectory(f'Empty directory: {capture_dir_str}') + raise MissingCaptureDirectory(f'Unable to find the UUID file in {capture_dir}.') # Get capture settings as they were submitted capture_settings_file = capture_dir / 'capture_settings.json'