diff --git a/app/application/transfer/execution.py b/app/application/transfer/execution.py index e441bad0c..7e5f47b8c 100644 --- a/app/application/transfer/execution.py +++ b/app/application/transfer/execution.py @@ -22,10 +22,6 @@ TRANSFER_EXECUTION_VERSION = 1 TRANSFER_STEP_INTENT_VERSION = 1 # 单步执行结果与探测证据的当前持久格式版本 TRANSFER_STEP_RESULT_VERSION = 1 -# 需要保留扩展名以兼容 115 重命名接口的内置及插件存储类型 -_115_RENAME_STORAGE_TYPES = frozenset({"u115", "115网盘Plus"}) - - class TransferExecutionState(StrEnum): """ 描述与规划阶段相互独立的持久执行状态。 @@ -161,9 +157,9 @@ def build_transfer_overwrite_paths( """ 从冻结叶操作推导同目录暂存和备份路径,保证执行与账本验证使用相同身份。 - 115 重命名会分割主文件名与扩展名,不能使用仅含点号前缀的无扩展名临时文件; - 内置 ``u115`` 与 P115Disk 的 ``115网盘Plus`` 临时名保留目标扩展名,其他存储 - 沿用原路径以保持已有步骤的恢复身份。 + 本地目录的临时名使用点号前缀且不带扩展名,避免进程中断后的残留被媒体扫描; + 其他存储统一使用非空主文件名并保留目标扩展名,兼容按主文件名和扩展名解析 + 重命名的远端接口。存储类型可以由插件动态注册,不能在宿主中维护插件名称名单。 """ identity = _canonical_json({ "source": dict(source), "storage": target_storage, @@ -171,9 +167,9 @@ def build_transfer_overwrite_paths( }) digest = hashlib.sha256(identity.encode("utf-8")).hexdigest()[:24] target = Path(target_path) - is_115_storage = target_storage in _115_RENAME_STORAGE_TYPES - prefix = "mp" if is_115_storage else ".mp" - suffix = target.suffix if is_115_storage else "" + is_local_storage = target_storage == "local" + prefix = ".mp" if is_local_storage else "mp" + suffix = "" if is_local_storage else target.suffix return ( target.with_name(f"{prefix}-stage-{digest}{suffix}").as_posix(), target.with_name(f"{prefix}-backup-{digest}{suffix}").as_posix(), diff --git a/tests/test_transfer_safe_overwrite.py b/tests/test_transfer_safe_overwrite.py index efa62e622..ac2bafd94 100644 --- a/tests/test_transfer_safe_overwrite.py +++ b/tests/test_transfer_safe_overwrite.py @@ -263,11 +263,11 @@ def test_u115_partial_native_copy_is_isolated_instead_of_repeated( @pytest.mark.parametrize("filename", ["美人余.S01E23.mkv", "Movie.MP4", "archive.tar.gz", "Movie"]) @pytest.mark.parametrize( - "storage", ["u115", "115网盘Plus", "local", "alist", "alipan", "smb", "rclone"], + "storage", ["u115", "115网盘Plus", "plugin-storage", "local", "alist", "alipan", "smb", "rclone"], ) def test_overwrite_paths_preserve_storage_filename_contract(filename: str, storage: str) -> None: """ - 115 内置及插件存储的临时名称保留扩展名且有主文件名,其他存储保持既有路径以兼容恢复。 + 本地临时名称保持隐藏且无扩展名,其他存储统一保留非空主文件名和目标扩展名。 """ arguments = { "source": {"storage": "local", "path": "/downloads/source.mkv"}, @@ -280,23 +280,23 @@ def test_overwrite_paths_preserve_storage_filename_contract(filename: str, stora for path, kind in zip(paths, ("stage", "backup")): item = Path(path) assert item.parent == Path("/library") - if storage in {"u115", "115网盘Plus"}: - assert item.name.startswith(f"mp-{kind}-") - assert item.suffix == Path(filename).suffix - else: + if storage == "local": assert item.name.startswith(f".mp-{kind}-") assert len(item.name) == len(f".mp-{kind}-") + 24 + else: + assert item.name.startswith(f"mp-{kind}-") + assert item.suffix == Path(filename).suffix -@pytest.mark.parametrize("storage", ["u115", "115网盘Plus"]) +@pytest.mark.parametrize("storage", ["u115", "115网盘Plus", "plugin-storage"]) @pytest.mark.parametrize("transfer_type", ["copy", "move"]) @pytest.mark.parametrize("failed_rename", [None, "backup", "promote"]) -def test_115_overwrite_obeys_rename_protocol( +def test_remote_overwrite_obeys_rename_protocol( tmp_path: Path, monkeypatch: pytest.MonkeyPatch, storage: str, transfer_type: str, failed_rename: Optional[str], ) -> None: """ - 在真实文件上回放 115 重命名协议,验证覆盖成功及失败时保留完整副本。 + 在真实文件上回放按主文件名和扩展名解析的远端重命名协议,验证覆盖成功及失败时保留完整副本。 """ source = tmp_path / "download.mkv" target = tmp_path / "美人余.S01E23.mkv"