Skip to content

Commit

Permalink
优化Mirror的运行流程
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-cq committed Dec 6, 2023
1 parent b4f6741 commit 10a42ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
12 changes: 6 additions & 6 deletions alist_sync/run_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -62,30 +62,30 @@ 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),
sync_target
)
logger.info(
"[%s -> %s] 复制任务信息全部创建完成。",
self.scaned_source_dir.base_path,
self.scanned_source_dir.base_path,
sync_target.base_path
)

Expand Down
23 changes: 17 additions & 6 deletions alist_sync/run_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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中有的"""
Expand All @@ -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
)

Expand Down

0 comments on commit 10a42ba

Please sign in to comment.