Skip to content

Commit

Permalink
fix(list_dir): check permissions before reading and remove . and $ fo…
Browse files Browse the repository at this point in the history
…lders
  • Loading branch information
MartinBelthle committed Dec 20, 2024
1 parent d8df7e9 commit d1ec7f8
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions antarest/study/storage/explorer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# This file is part of the Antares project.

import logging
import os
from typing import List

from antarest.core.config import Config
Expand Down Expand Up @@ -40,11 +41,19 @@ def list_dir(
workspace = get_workspace_from_config(self.config, workspace_name, default_allowed=False)
directory_path = get_folder_from_workspace(workspace, workspace_directory_path)
directories = []
for child in directory_path.iterdir():
if child.is_dir() and not is_study_folder(child) and not should_ignore_folder_for_scan(child):
# we don't want to expose the full absolute path on the server
child_rel_path = child.relative_to(workspace.path)
directories.append(NonStudyFolderDTO(path=child_rel_path, workspace=workspace_name, name=child.name))
if os.access(directory_path, os.R_OK): # we don't want to try to read folders we can't access
for child in directory_path.iterdir():
if (
child.is_dir()
and not is_study_folder(child)
and not should_ignore_folder_for_scan(child)
and not child.name.startswith((".", "$"))
):
# we don't want to expose the full absolute path on the server
child_rel_path = child.relative_to(workspace.path)
directories.append(
NonStudyFolderDTO(path=child_rel_path, workspace=workspace_name, name=child.name)
)
return directories

def list_workspaces(
Expand Down

0 comments on commit d1ec7f8

Please sign in to comment.