diff --git a/antarest/study/storage/explorer_service.py b/antarest/study/storage/explorer_service.py index de383c9afa..adf82627df 100644 --- a/antarest/study/storage/explorer_service.py +++ b/antarest/study/storage/explorer_service.py @@ -47,15 +47,21 @@ def list_dir( children = list(directory_path.iterdir()) for child in children: # if we can't acess one child we skip it - if is_non_study_folder(child, workspace.filter_in, workspace.filter_out): - # we don't want to expose the full absolute path on the server - child_rel_path = child.relative_to(workspace.path) - has_children = has_non_study_folder(child, workspace.filter_in, workspace.filter_out) - directories.append( - NonStudyFolderDTO( - path=child_rel_path, workspace=workspace_name, name=child.name, has_children=has_children + try: + if is_non_study_folder(child, workspace.filter_in, workspace.filter_out): + # we don't want to expose the full absolute path on the server + child_rel_path = child.relative_to(workspace.path) + has_children = has_non_study_folder(child, workspace.filter_in, workspace.filter_out) + directories.append( + NonStudyFolderDTO( + path=child_rel_path, + workspace=workspace_name, + name=child.name, + has_children=has_children, + ) ) - ) + except PermissionError as e: + logger.warning(f"Permission error while accessing {child} or one of its children: {e}") except PermissionError as e: logger.warning(f"Permission error while listing {directory_path}: {e}") return directories diff --git a/antarest/study/storage/utils.py b/antarest/study/storage/utils.py index e6bc4d222d..787063ec98 100644 --- a/antarest/study/storage/utils.py +++ b/antarest/study/storage/utils.py @@ -478,49 +478,37 @@ def is_ts_gen_tmp_dir(path: Path) -> bool: def should_ignore_folder_for_scan(path: Path, filter_in: t.List[str], filter_out: t.List[str]) -> bool: - try: - if is_aw_no_scan(path): - logger.info(f"No scan directive file found. Will skip further scan of folder {path}") - return True - - if is_temporary_upgrade_dir(path): - logger.info(f"Upgrade temporary folder found. Will skip further scan of folder {path}") - return True + if is_aw_no_scan(path): + logger.info(f"No scan directive file found. Will skip further scan of folder {path}") + return True - if is_ts_gen_tmp_dir(path): - logger.info(f"TS generation temporary folder found. Will skip further scan of folder {path}") - return True + if is_temporary_upgrade_dir(path): + logger.info(f"Upgrade temporary folder found. Will skip further scan of folder {path}") + return True - return not ( - path.is_dir() - and any(re.search(regex, path.name) for regex in filter_in) - and not any(re.search(regex, path.name) for regex in filter_out) - ) - except PermissionError as e: - logger.warning(f"Permission error while accessing {path}: {e}") + if is_ts_gen_tmp_dir(path): + logger.info(f"TS generation temporary folder found. Will skip further scan of folder {path}") return True + return not ( + path.is_dir() + and any(re.search(regex, path.name) for regex in filter_in) + and not any(re.search(regex, path.name) for regex in filter_out) + ) + def has_non_study_folder(path: Path, filter_in: t.List[str], filter_out: t.List[str]) -> bool: - try: - for sub_path in path.iterdir(): - if is_non_study_folder(sub_path, filter_in, filter_out): - return True - return False - except PermissionError as e: - logger.warning(f"Permission error while accessing {path}: {e}") - return False + for sub_path in path.iterdir(): + if is_non_study_folder(sub_path, filter_in, filter_out): + return True + return False def is_non_study_folder(path: Path, filter_in: t.List[str], filter_out: t.List[str]) -> bool: - try: - if not path.is_dir(): - return False - if is_study_folder(path): - return False - if should_ignore_folder_for_scan(path, filter_in, filter_out): - return False - return True - except PermissionError as e: - logger.warning(f"Permission error while accessing {path}: {e}") + if not path.is_dir(): + return False + if is_study_folder(path): return False + if should_ignore_folder_for_scan(path, filter_in, filter_out): + return False + return True