diff --git a/driveutil/fix-hah/app/_main.py b/driveutil/fix-hah/app/_main.py index aebc4300..59243822 100644 --- a/driveutil/fix-hah/app/_main.py +++ b/driveutil/fix-hah/app/_main.py @@ -3,6 +3,7 @@ from pathlib import Path from tempfile import TemporaryDirectory +from wcpan.drive.core.types import Drive, Node from wcpan.drive.cli.lib import create_drive_from_config from wcpan.logging import ConfigBuilder @@ -32,11 +33,7 @@ async def main(args: list[str]) -> int: children = (_ for _ in children if _is_hah_name(_.name)) for child in children: - src_path = await download(drive, child, work_path) - tmp_path = await archive(src_path, work_path) - await upload(drive, tmp_path, node) - await drive.move(child, trashed=True) - print(f"remove {child}") + await _migrate(drive, child, work_path, node) await sleep(60) return 0 @@ -46,3 +43,11 @@ def _is_hah_name(name: str) -> bool: rv = re.search(r"\[\d+\]$", name) return rv is not None + + +async def _migrate(drive: Drive, src: Node, tmp: Path, parent: Node) -> None: + src_path = await download(drive, src, tmp) + tmp_path = await archive(src_path, tmp) + await upload(drive, tmp_path, parent) + await drive.move(src, trashed=True) + print(f"remove {src}")