From df0b7486efa17a4867a1ad83a78d0e8e345e38de Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 20 Oct 2024 14:39:44 -0600 Subject: [PATCH] Handling getting primary file when a file is deleted. --- wrolpi/files/lib.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wrolpi/files/lib.py b/wrolpi/files/lib.py index de7aab6c..2f34b562 100644 --- a/wrolpi/files/lib.py +++ b/wrolpi/files/lib.py @@ -362,7 +362,17 @@ def get_primary_file(files: Union[Tuple[pathlib.Path], Iterable[pathlib.Path]]) # Only one file is always the primary. return files[0] - file_mimetypes = [(i, get_mimetype(i)) for i in files] + file_mimetypes = list() + for idx, i in enumerate(files): + try: + file_mimetypes.append((i, get_mimetype(i))) + except FileNotFoundError: + # File was deleted. + pass + + if not file_mimetypes: + raise FileNotFoundError(f'Cannot find primary file. All files are no longer accessible: {files[0]}') + # EPUB has high priority. mimetypes = {i[1] for i in file_mimetypes} has_epub = any(i.startswith('application/epub') for i in mimetypes)