real path should not be used when creating distination file list.

This commit is contained in:
Yoshihiro OKUMURA 2023-12-18 16:23:46 +09:00
parent 292ca1df27
commit 9284346153
Signed by: orrisroot
GPG Key ID: 470AA444C92904B2
2 changed files with 5 additions and 5 deletions

View File

@ -1,3 +1,4 @@
import os
from typing import Any, Final from typing import Any, Final
from pydantic import TypeAdapter from pydantic import TypeAdapter
@ -31,7 +32,7 @@ class FilesApi(BaseApi):
token_check(self.connection) token_check(self.connection)
data: dict[str, str | int] = {"folder_id": folder_id} data: dict[str, str | int] = {"folder_id": folder_id}
try: 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}) response = self.connection.post(url, data=data, files={"file": fp})
self._raise_response_error(response) self._raise_response_error(response)
ret = TypeAdapter(FilesApiCreateResponse).validate_python(response.json()) ret = TypeAdapter(FilesApiCreateResponse).validate_python(response.json())
@ -46,7 +47,7 @@ class FilesApi(BaseApi):
if path is not None: if path is not None:
# update file body # update file body
try: 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}) response = self.connection.put(url, files={"file": fp})
except OSError: except OSError:
raise UnexpectedException(f"Could not open `{path}` file.") raise UnexpectedException(f"Could not open `{path}` file.")

View File

@ -40,7 +40,7 @@ class UploadCommand(BaseCommand):
@classmethod @classmethod
def upload(cls, local_path: str, remote_path: str, is_recursive: bool) -> None: 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) (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): if not os.path.exists(l_path):
raise IllegalArgumentException(f"File or directory `{local_path}` not found.") raise IllegalArgumentException(f"File or directory `{local_path}` not found.")
connection = cls._create_connection(remote) connection = cls._create_connection(remote)
@ -55,8 +55,7 @@ class UploadCommand(BaseCommand):
folder_map[r_path] = folder folder_map[r_path] = folder
l_basename = os.path.basename(l_path) l_basename = os.path.basename(l_path)
for dirpath, _, filenames in os.walk(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, l_basename)
d_dirname = os.path.join(r_path, sub)
d_basename = os.path.basename(d_dirname) d_basename = os.path.basename(d_dirname)
# prepare destination parent path # prepare destination parent path
d_parent_dirname = os.path.dirname(d_dirname) d_parent_dirname = os.path.dirname(d_dirname)