Skip to content

Commit

Permalink
Make /my_files/ return absolute paths
Browse files Browse the repository at this point in the history
Fixes ecotaxa#56.
  • Loading branch information
moi90 committed Feb 16, 2023
1 parent 2ff03f0 commit 33de13f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion py/API_operations/UserFolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def list_and_format(a_dir: Union[UserDirectory, CommonFolder], sub_path: str) ->
# Format data to return
entries = [DirectoryEntryModel(name=a_name, type=a_type, size=a_size, mtime=a_mtime)
for (a_name, a_type, a_size, a_mtime) in listing]
return DirectoryModel(path=sub_path, entries=entries)
return DirectoryModel(path=a_dir.absolute_path(sub_path), entries=entries)


class CommonFolderService(Service):
Expand Down
6 changes: 4 additions & 2 deletions py/FS/CommonDir.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ def path_to(self, sub_path: str) -> str:
sub_path = sub_path.lstrip("/")
return self.path.joinpath(sub_path).as_posix()

def absolute_path(self, sub_path: str):
return Path(self.path.joinpath(sub_path)).absolute()

def list(self, sub_path: str) -> List[DirEntryT]:
"""
List given sub-path, returning the name of entries and details of zip files.
"""
ret: List[DirEntryT] = []
# Leading / implies root directory
sub_path = sub_path.lstrip("/")
abs_path = Path(self.path.joinpath(sub_path))
return self.list_dir_into(abs_path, ret)
return self.list_dir_into(self.absolute_path(sub_path), ret)

@staticmethod
def list_dir_into(abs_path, out):
Expand Down
7 changes: 5 additions & 2 deletions py/FS/UserDir.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ async def add_file(self, name: str, path: Optional[str], stream: Any) -> str:
buff = await stream.read(1024)
return str(dest_path)

def absolute_path(self, sub_path: str):
return Path(tempfile.gettempdir(), self.USER_DIR_PATTERN % self.user_id, sub_path).absolute()

def list(self, sub_path: str) -> List[DirEntryT]:
"""
Only list the known (with tags) directory.
"""
# Leading / implies root directory
sub_path = sub_path.lstrip("/")
ret: List[DirEntryT] = []
path: Path = Path(tempfile.gettempdir(), self.USER_DIR_PATTERN % self.user_id, sub_path)
CommonFolder.list_dir_into(path, ret)

CommonFolder.list_dir_into(self.absolute_path(sub_path), ret)
return ret

def contains(self, path_str: str) -> bool:
Expand Down

0 comments on commit 33de13f

Please sign in to comment.