From ce0a608db292b45ef859cc678c25e62dff7a5b63 Mon Sep 17 00:00:00 2001 From: Yoshihiro OKUMURA Date: Wed, 20 Dec 2023 19:42:06 +0900 Subject: [PATCH] fixed bug to resolve local files for recursive file upload. --- .cspell.json | 2 +- mdrsclient/VERSION | 2 +- mdrsclient/api/files.py | 4 ++-- mdrsclient/commands/upload.py | 7 ++++--- pyproject.toml | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.cspell.json b/.cspell.json index b742e8d..e8d8ae2 100644 --- a/.cspell.json +++ b/.cspell.json @@ -1,7 +1,7 @@ { "version": "0.2", "language": "en,en-gb", - "ignoreWords": ["getframe", "pycache", "pydantic", "UNLCK"], + "ignoreWords": ["followlinks", "getframe", "pycache", "pydantic", "UNLCK"], "words": [ "chacl", "kikan", diff --git a/mdrsclient/VERSION b/mdrsclient/VERSION index f0bb29e..3a3cd8c 100644 --- a/mdrsclient/VERSION +++ b/mdrsclient/VERSION @@ -1 +1 @@ -1.3.0 +1.3.1 diff --git a/mdrsclient/api/files.py b/mdrsclient/api/files.py index cc4a4ef..5fc5e7a 100644 --- a/mdrsclient/api/files.py +++ b/mdrsclient/api/files.py @@ -32,7 +32,7 @@ class FilesApi(BaseApi): token_check(self.connection) data: dict[str, str | int] = {"folder_id": folder_id} try: - with open(os.path.relpath(path), mode="rb") as fp: + with open(os.path.realpath(path), mode="rb") as fp: response = self.connection.post(url, data=data, files={"file": fp}) self._raise_response_error(response) ret = TypeAdapter(FilesApiCreateResponse).validate_python(response.json()) @@ -47,7 +47,7 @@ class FilesApi(BaseApi): if path is not None: # update file body try: - with open(os.path.relpath(path), mode="rb") as fp: + with open(os.path.realpath(path), mode="rb") as fp: response = self.connection.put(url, files={"file": fp}) except OSError: raise UnexpectedException(f"Could not open `{path}` file.") diff --git a/mdrsclient/commands/upload.py b/mdrsclient/commands/upload.py index c12f83f..cc683b2 100644 --- a/mdrsclient/commands/upload.py +++ b/mdrsclient/commands/upload.py @@ -40,7 +40,7 @@ class UploadCommand(BaseCommand): @classmethod def upload(cls, local_path: str, remote_path: str, is_recursive: bool) -> None: (remote, laboratory_name, r_path) = cls._parse_remote_host_with_path(remote_path) - l_path = local_path + l_path = os.path.abspath(local_path) if not os.path.exists(l_path): raise IllegalArgumentException(f"File or directory `{local_path}` not found.") connection = cls._create_connection(remote) @@ -54,8 +54,9 @@ class UploadCommand(BaseCommand): folder_map: dict[str, Folder] = {} folder_map[r_path] = folder l_basename = os.path.basename(l_path) - for dirpath, _, filenames in os.walk(l_path): - d_dirname = os.path.join(r_path, l_basename) + for dirpath, _, filenames in os.walk(l_path, followlinks=True): + sub = l_basename if dirpath == l_path else os.path.join(l_basename, os.path.relpath(dirpath, l_path)) + d_dirname = os.path.join(r_path, sub) d_basename = os.path.basename(d_dirname) # prepare destination parent path d_parent_dirname = os.path.dirname(d_dirname) diff --git a/pyproject.toml b/pyproject.toml index afe55d4..6b75aaf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mdrs-client-python" -version = "1.3.0" +version = "1.3.1" description = "The mdrs-client-python is python library and a command-line client for up- and downloading files to and from MDRS based repository." authors = ["Yoshihiro OKUMURA "] license = "MIT"