From 10a42ba2981a4ad992aecb5d38eabf0f6df8507b Mon Sep 17 00:00:00 2001 From: LeeCQ Date: Wed, 6 Dec 2023 11:56:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96Mirror=E7=9A=84=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- alist_sync/run_copy.py | 12 ++++++------ alist_sync/run_mirror.py | 23 +++++++++++++++++------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/alist_sync/run_copy.py b/alist_sync/run_copy.py index b87d21d..c8111b7 100644 --- a/alist_sync/run_copy.py +++ b/alist_sync/run_copy.py @@ -25,7 +25,7 @@ async def async_run(self): # 创建复制列表 if not self.sync_task.copy_tasks: - await self.create_copy_list() + self.create_copy_list() self.save_to_cache() else: logger.info(f"一件从缓存中找到 %d 个 CopyTask", @@ -62,22 +62,22 @@ def create_copy_task(self, source: SyncDir, target: SyncDir): source.base_path, target.base_path, copy_path) @property - def scaned_source_dir(self) -> SyncDir: + def scanned_source_dir(self) -> SyncDir: _s = self.sync_task.sync_dirs.get(self.source_path) if _s is None: raise # TODO return _s @property - def scaned_targets_dir(self) -> list[SyncDir]: + def scanned_targets_dir(self) -> list[SyncDir]: _ts = [self.sync_task.sync_dirs.get(t) for t in self.targets_path] if _ts: return _ts raise # TODO - async def create_copy_list(self): + def create_copy_list(self): - for sync_target in self.scaned_targets_dir: + for sync_target in self.scanned_targets_dir: sync_target: SyncDir self.create_copy_task( self.sync_task.sync_dirs.get(self.source_path), @@ -85,7 +85,7 @@ async def create_copy_list(self): ) logger.info( "[%s -> %s] 复制任务信息全部创建完成。", - self.scaned_source_dir.base_path, + self.scanned_source_dir.base_path, sync_target.base_path ) diff --git a/alist_sync/run_mirror.py b/alist_sync/run_mirror.py index 6cf8e7d..2727179 100644 --- a/alist_sync/run_mirror.py +++ b/alist_sync/run_mirror.py @@ -31,7 +31,17 @@ def __init__(self, alist_info, targets_path=targets_path) async def async_run(self): - await super().async_run() + await super(CopyToTarget).async_run() + # 创建复制列表 + if not self.sync_task.copy_tasks: + self.create_copy_list() + self.save_to_cache() + else: + logger.info(f"一件从缓存中找到 %d 个 CopyTask", + len(self.sync_task.copy_tasks)) + + # 复制文件 + asyncio.create_task(self.copy_files(), name="copy_files") # 创建删除列表 if not self.sync_task.remove_tasks: @@ -43,9 +53,10 @@ async def async_run(self): logger.info( f"一件从缓存中找到 %d 个 RemoveTask", len(self.sync_task.remove_tasks) ) + await self.remove_files() # 删除文件 - # 删除文件 - await self.remove_files() + await self.check_status() + logger.info("复制完成。") def create_remove_task(self, source_dir: SyncDir, target_dir: SyncDir): """source无,删除target中有的""" @@ -67,13 +78,13 @@ def create_remove_task(self, source_dir: SyncDir, target_dir: SyncDir): logger.info("添加RemoveTask:%s", item.full_name) def create_remove_list(self): - for sync_target in self.scaned_targets_dir: + for sync_target in self.scanned_targets_dir: sync_target: SyncDir self.create_remove_task( - self.scaned_source_dir, sync_target) + self.scanned_source_dir, sync_target) logger.info( "[%s -> %s] 删除任务信息全部创建完成。", - self.scaned_source_dir.base_path, + self.scanned_source_dir.base_path, sync_target.base_path )