From 03d118a73a2610f1a36b3bbbffd31b61ba02c0a9 Mon Sep 17 00:00:00 2001 From: Shawn Lu Date: Thu, 26 Feb 2026 23:43:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=98=BF=E9=87=8C?= =?UTF-8?q?=E4=BA=91=E7=9B=98=E7=9B=AE=E5=BD=95=E7=9B=91=E6=8E=A7=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E6=97=A0=E6=B3=95=E6=A3=80=E6=B5=8B=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 为阿里云盘添加 ALIPAN_SNAPSHOT_CHECK_FOLDER_MODTIME 配置(默认 False) - 阿里云盘目录的 updated_at 不会随子文件变更而更新,导致增量快照 始终跳过目录,快照结果为空 - 与 Rclone/Alist 保持一致的配置模式 2. 移除 snapshot() 中文件级 modify_time 过滤 - 原逻辑:仅包含 modify_time > last_snapshot_time 的文件 - 问题:首次快照建立基准后,save_snapshot 将 timestamp 设为 max(modify_times),后续快照中未变更的文件因 modify_time 不大于 timestamp 而被排除,导致 compare_snapshots 无法检测到任何变化 - 此外当 last_snapshot_time 为 None 时,比较会触发 TypeError 并被静默捕获 - 修复:始终包含所有遍历到的文件,由 compare_snapshots 负责变化检测 目录级优化仍由 snapshot_check_folder_modtime 控制 Co-Authored-By: Claude Opus 4.6 --- app/core/config.py | 2 ++ app/modules/filemanager/storages/__init__.py | 13 ++++++------- app/modules/filemanager/storages/alipan.py | 3 +++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 121736f4..3aa24626 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -414,6 +414,8 @@ class ConfigModel(BaseModel): RCLONE_SNAPSHOT_CHECK_FOLDER_MODTIME: bool = True # 对OpenList进行快照对比时,是否检查文件夹的修改时间 OPENLIST_SNAPSHOT_CHECK_FOLDER_MODTIME: bool = True + # 对阿里云盘进行快照对比时,是否检查文件夹的修改时间(默认关闭,因为阿里云盘目录时间不随子文件变更而更新) + ALIPAN_SNAPSHOT_CHECK_FOLDER_MODTIME: bool = False # ==================== Docker配置 ==================== # Docker Client API地址 diff --git a/app/modules/filemanager/storages/__init__.py b/app/modules/filemanager/storages/__init__.py index 267e8080..3adeca74 100644 --- a/app/modules/filemanager/storages/__init__.py +++ b/app/modules/filemanager/storages/__init__.py @@ -261,13 +261,12 @@ class StorageBase(metaclass=ABCMeta): for sub_file in sub_files: __snapshot_file(sub_file, current_depth + 1) else: - # 记录文件的完整信息用于比对 - if getattr(_fileitm, 'modify_time', 0) > last_snapshot_time: - files_info[_fileitm.path] = { - 'size': _fileitm.size or 0, - 'modify_time': getattr(_fileitm, 'modify_time', 0), - 'type': _fileitm.type - } + # 记录文件的完整信息用于比对(始终包含所有文件,由 compare_snapshots 负责检测变化) + files_info[_fileitm.path] = { + 'size': _fileitm.size or 0, + 'modify_time': getattr(_fileitm, 'modify_time', 0), + 'type': _fileitm.type + } except Exception as e: logger.debug(f"Snapshot error for {_fileitm.path}: {e}") diff --git a/app/modules/filemanager/storages/alipan.py b/app/modules/filemanager/storages/alipan.py index fd6040a7..0c18d141 100644 --- a/app/modules/filemanager/storages/alipan.py +++ b/app/modules/filemanager/storages/alipan.py @@ -43,6 +43,9 @@ class AliPan(StorageBase, metaclass=WeakSingleton): # 基础url base_url = "https://openapi.alipan.com" + # 阿里云盘目录时间不随子文件变更而更新,默认关闭目录修改时间检查 + snapshot_check_folder_modtime = settings.ALIPAN_SNAPSHOT_CHECK_FOLDER_MODTIME + # 文件块大小,默认10MB chunk_size = 10 * 1024 * 1024