Multiple folder move added

This commit is contained in:
kodi
2026-03-11 16:27:21 +01:00
parent 3e4761f5a7
commit 6e7b3cffae
14 changed files with 428 additions and 43 deletions
+54
View File
@@ -43,6 +43,14 @@ class TaskRunner:
)
thread.start()
def enqueue_move_batch(self, task_id: str, items: list[dict[str, str]]) -> None:
thread = threading.Thread(
target=self._run_move_batch,
args=(task_id, items),
daemon=True,
)
thread.start()
def _run_copy_file(self, task_id: str, source: str, destination: str, total_bytes: int) -> None:
self._repository.mark_running(
task_id=task_id,
@@ -156,3 +164,49 @@ class TaskRunner:
done_items=0,
total_items=1,
)
def _run_move_batch(self, task_id: str, items: list[dict[str, str]]) -> None:
total_items = len(items)
current_item = items[0]["source"] if items else None
self._repository.mark_running(
task_id=task_id,
done_items=0,
total_items=total_items,
current_item=current_item,
)
completed_items = 0
for index, item in enumerate(items):
source = item["source"]
destination = item["destination"]
try:
if item["kind"] == "directory":
self._filesystem.move_directory(source=source, destination=destination)
else:
self._filesystem.move_file(source=source, destination=destination)
completed_items = index + 1
next_item = items[index + 1]["source"] if index + 1 < total_items else source
self._repository.update_progress(
task_id=task_id,
done_items=completed_items,
total_items=total_items,
current_item=next_item,
)
except OSError as exc:
self._repository.mark_failed(
task_id=task_id,
error_code="io_error",
error_message=str(exc),
failed_item=source,
done_bytes=None,
total_bytes=None,
done_items=completed_items,
total_items=total_items,
)
return
self._repository.mark_completed(
task_id=task_id,
done_items=total_items,
total_items=total_items,
)