add new command cp.

This commit is contained in:
2023-07-20 11:43:07 +09:00
parent 08d8a0626a
commit 4d87b55b40
9 changed files with 152 additions and 10 deletions

View File

@ -9,7 +9,7 @@ from pydantic import TypeAdapter
from mdrsclient.api import FileApi, FolderApi
from mdrsclient.commands.base import BaseCommand
from mdrsclient.exceptions import IllegalArgumentException
from mdrsclient.models import File, FolderSimple
from mdrsclient.models import FolderSimple
class MvCommand(BaseCommand):
@ -58,9 +58,7 @@ class MvCommand(BaseCommand):
raise IllegalArgumentException(f"Cannot overwrite non-folder `{d_basename}` with folder `{d_path}`.")
file_api = FileApi(connection)
if s_parent_folder.id != d_parent_folder.id or d_basename != s_basename:
d_file_dict = dataclasses.asdict(s_file) | {"name": normalize("NFC", d_basename)}
d_file = TypeAdapter(File).validate_python(d_file_dict)
file_api.move(d_file, d_parent_folder.id)
file_api.move(s_file, d_parent_folder.id, normalize("NFC", d_basename))
else:
s_folder = s_parent_folder.find_sub_folder(s_basename)
if s_folder is None: