From b155166880a76b590a6639111637f06d2220a24f Mon Sep 17 00:00:00 2001 From: Lukas Rothenberger Date: Fri, 8 Dec 2023 10:51:05 +0100 Subject: [PATCH] fix(file_mapping): make more robust to deletions and invalid file paths --- discopop_explorer/parser.py | 2 ++ discopop_library/PathManagement/PathManagement.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/discopop_explorer/parser.py b/discopop_explorer/parser.py index 802229a8f..5c2aa9f54 100644 --- a/discopop_explorer/parser.py +++ b/discopop_explorer/parser.py @@ -215,6 +215,8 @@ def is_reduction(reduction_line, fmap_lines, file_mapping): file_line = int(res.group(2)) filepath = get_filepath(file_id, fmap_lines, file_mapping) + if not os.path.exists(filepath): + return False src_file = open(filepath) src_lines = src_file.read().splitlines() src_file.close() diff --git a/discopop_library/PathManagement/PathManagement.py b/discopop_library/PathManagement/PathManagement.py index 8ca398779..e2f625f11 100644 --- a/discopop_library/PathManagement/PathManagement.py +++ b/discopop_library/PathManagement/PathManagement.py @@ -23,7 +23,8 @@ def load_file_mapping(fmap_path: str) -> Dict[int, Path]: split_line = line.split("\t") file_id = int(split_line[0]) file_path = split_line[1] - file_mapping[file_id] = Path(file_path) + if os.path.exists(file_path): + file_mapping[file_id] = Path(file_path) return file_mapping