diff --git a/py/API_operations/UserFolder.py b/py/API_operations/UserFolder.py index 8383984c..f27ad1e5 100644 --- a/py/API_operations/UserFolder.py +++ b/py/API_operations/UserFolder.py @@ -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): diff --git a/py/FS/CommonDir.py b/py/FS/CommonDir.py index a2ebcabc..239f2ca1 100644 --- a/py/FS/CommonDir.py +++ b/py/FS/CommonDir.py @@ -27,6 +27,9 @@ 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. @@ -34,8 +37,7 @@ def list(self, sub_path: str) -> List[DirEntryT]: 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): diff --git a/py/FS/UserDir.py b/py/FS/UserDir.py index fa1b9ccd..9f21251f 100644 --- a/py/FS/UserDir.py +++ b/py/FS/UserDir.py @@ -55,6 +55,9 @@ 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. @@ -62,8 +65,8 @@ def list(self, sub_path: str) -> List[DirEntryT]: # 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: