mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-11-24 21:03:48 +08:00
Merge pull request #7309 from jxxghp/fix/issue-7306-115-overwrite
fix(transfer): 修复第三方 115 覆盖整理临时文件名
This commit is contained in:
@@ -22,6 +22,8 @@ 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):
|
||||
@@ -160,7 +162,8 @@ def build_transfer_overwrite_paths(
|
||||
从冻结叶操作推导同目录暂存和备份路径,保证执行与账本验证使用相同身份。
|
||||
|
||||
115 重命名会分割主文件名与扩展名,不能使用仅含点号前缀的无扩展名临时文件;
|
||||
其临时名保留目标扩展名,其他存储沿用原路径以保持已有步骤的恢复身份。
|
||||
内置 ``u115`` 与 P115Disk 的 ``115网盘Plus`` 临时名保留目标扩展名,其他存储
|
||||
沿用原路径以保持已有步骤的恢复身份。
|
||||
"""
|
||||
identity = _canonical_json({
|
||||
"source": dict(source), "storage": target_storage,
|
||||
@@ -168,8 +171,9 @@ def build_transfer_overwrite_paths(
|
||||
})
|
||||
digest = hashlib.sha256(identity.encode("utf-8")).hexdigest()[:24]
|
||||
target = Path(target_path)
|
||||
prefix = "mp" if target_storage == "u115" else ".mp"
|
||||
suffix = target.suffix if target_storage == "u115" else ""
|
||||
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 ""
|
||||
return (
|
||||
target.with_name(f"{prefix}-stage-{digest}{suffix}").as_posix(),
|
||||
target.with_name(f"{prefix}-backup-{digest}{suffix}").as_posix(),
|
||||
|
||||
@@ -262,10 +262,12 @@ 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", "local", "alist", "alipan", "smb", "rclone"])
|
||||
@pytest.mark.parametrize(
|
||||
"storage", ["u115", "115网盘Plus", "local", "alist", "alipan", "smb", "rclone"],
|
||||
)
|
||||
def test_overwrite_paths_preserve_storage_filename_contract(filename: str, storage: str) -> None:
|
||||
"""
|
||||
115 临时名称保留扩展名且有主文件名,其他存储保持既有路径以兼容恢复。
|
||||
115 内置及插件存储的临时名称保留扩展名且有主文件名,其他存储保持既有路径以兼容恢复。
|
||||
"""
|
||||
arguments = {
|
||||
"source": {"storage": "local", "path": "/downloads/source.mkv"},
|
||||
@@ -278,7 +280,7 @@ 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 == "u115":
|
||||
if storage in {"u115", "115网盘Plus"}:
|
||||
assert item.name.startswith(f"mp-{kind}-")
|
||||
assert item.suffix == Path(filename).suffix
|
||||
else:
|
||||
@@ -286,11 +288,12 @@ def test_overwrite_paths_preserve_storage_filename_contract(filename: str, stora
|
||||
assert len(item.name) == len(f".mp-{kind}-") + 24
|
||||
|
||||
|
||||
@pytest.mark.parametrize("storage", ["u115", "115网盘Plus"])
|
||||
@pytest.mark.parametrize("transfer_type", ["copy", "move"])
|
||||
@pytest.mark.parametrize("failed_rename", [None, "backup", "promote"])
|
||||
def test_u115_overwrite_obeys_rename_protocol(
|
||||
def test_115_overwrite_obeys_rename_protocol(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
|
||||
transfer_type: str, failed_rename: Optional[str],
|
||||
storage: str, transfer_type: str, failed_rename: Optional[str],
|
||||
) -> None:
|
||||
"""
|
||||
在真实文件上回放 115 重命名协议,验证覆盖成功及失败时保留完整副本。
|
||||
@@ -313,7 +316,7 @@ def test_u115_overwrite_obeys_rename_protocol(
|
||||
return None
|
||||
identifier = str(path.stat().st_ino)
|
||||
identifiers[int(identifier)] = path
|
||||
return item.model_copy(update={"storage": "u115", "fileid": identifier})
|
||||
return item.model_copy(update={"storage": storage, "fileid": identifier})
|
||||
|
||||
def upload(folder: FileItem, path: Path, name: str) -> Optional[FileItem]:
|
||||
"""
|
||||
@@ -349,7 +352,7 @@ def test_u115_overwrite_obeys_rename_protocol(
|
||||
source_item = local.get_item_strict(source).model_dump(mode="json")
|
||||
arguments = {
|
||||
"step_runner": _ImmediateStepRunner(), "source_fileitem": source_item,
|
||||
"target_storage": "u115", "source_oper": local, "target_oper": remote,
|
||||
"target_storage": storage, "source_oper": local, "target_oper": remote,
|
||||
"target_file": target, "transfer_type": transfer_type,
|
||||
}
|
||||
execute = TransHandler._TransHandler__replace_target_with_steps
|
||||
|
||||
Reference in New Issue
Block a user