From 9284346153ccdc67e11d3a846ebedc1961788e92 Mon Sep 17 00:00:00 2001 From: Yoshihiro OKUMURA Date: Mon, 18 Dec 2023 16:23:46 +0900 Subject: [PATCH] real path should not be used when creating distination file list. --- mdrsclient/api/files.py | 5 +++-- mdrsclient/commands/upload.py | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mdrsclient/api/files.py b/mdrsclient/api/files.py index fb5e9e5..cc4a4ef 100644 --- a/mdrsclient/api/files.py +++ b/mdrsclient/api/files.py @@ -1,3 +1,4 @@ +import os from typing import Any, Final from pydantic import TypeAdapter @@ -31,7 +32,7 @@ class FilesApi(BaseApi): token_check(self.connection) data: dict[str, str | int] = {"folder_id": folder_id} try: - with open(path, mode="rb") as fp: + with open(os.path.relpath(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()) @@ -46,7 +47,7 @@ class FilesApi(BaseApi): if path is not None: # update file body try: - with open(path, mode="rb") as fp: + with open(os.path.relpath(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 5ff258e..c12f83f 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 = os.path.realpath(local_path) + l_path = local_path if not os.path.exists(l_path): raise IllegalArgumentException(f"File or directory `{local_path}` not found.") connection = cls._create_connection(remote) @@ -55,8 +55,7 @@ class UploadCommand(BaseCommand): folder_map[r_path] = folder l_basename = os.path.basename(l_path) for dirpath, _, filenames in os.walk(l_path): - 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_dirname = os.path.join(r_path, l_basename) d_basename = os.path.basename(d_dirname) # prepare destination parent path d_parent_dirname = os.path.dirname(d_dirname)