Detect storage migration overwrite risk

这个提交存在于:
YokiiroBW 2026-07-05 19:47:37 +08:00
父节点 c15c9d83ca
当前提交 49fe0208a6
共有 2 个文件被更改,包括 21 次插入 和 3 次删除

查看文件

@ -48,7 +48,7 @@ class VfsStorage:
{"field": "dry_run"},
)
source_path = self.resolve_uri(source_uri)
self.resolve_uri(target_uri)
target_path = self.resolve_uri(target_uri)
if not source_path.exists():
raise ApiError(ErrorCode.MEDIA_NOT_FOUND, "source media not found", {"uri": source_uri})
files, total_bytes = _path_file_stats(source_path)
@ -59,7 +59,7 @@ class VfsStorage:
"target_uri": target_uri,
"files": files,
"bytes": total_bytes,
"will_overwrite": False,
"will_overwrite": target_path.exists(),
"execution_enabled": False,
}

查看文件

@ -91,6 +91,7 @@ class S2RouteTests(unittest.TestCase):
images_path = (self.root / "images").as_posix()
thumbnails_path = (self.root / "thumbnails").as_posix()
materials_path = (self.root / "materials").as_posix()
archives_path = (self.root / "archives").as_posix()
temp_path = (self.root / "temp").as_posix()
self.config_path.write_text(
f"""
@ -110,11 +111,12 @@ storage:
images_path: "{images_path}"
thumbnails_path: "{thumbnails_path}"
materials_path: "{materials_path}"
archives_path: "{archives_path}"
temp_path: "{temp_path}"
""",
encoding="utf-8",
)
for folder in ("images", "thumbnails", "materials", "temp"):
for folder in ("images", "thumbnails", "materials", "archives", "temp"):
(self.root / folder).mkdir(parents=True, exist_ok=True)
(self.root / "images" / "sample.bin").write_bytes(b"12345")
(self.root / "materials" / "sample.bin").write_bytes(b"abc")
@ -639,8 +641,24 @@ database:
self.assertTrue(planned["data"]["dry_run"])
self.assertEqual(planned["data"]["files"], 1)
self.assertEqual(planned["data"]["bytes"], 5)
self.assertFalse(planned["data"]["will_overwrite"])
self.assertNotIn(str(self.root), str(planned["data"]))
(self.root / "archives").mkdir(parents=True, exist_ok=True)
(self.root / "archives" / "sample.bin").write_bytes(b"old")
overwrite_plan = migrate_storage(
self.ctx,
{
"source_uri": "storage://images/sample.bin",
"target_uri": "storage://archives/sample.bin",
"dry_run": True,
},
self.media_service,
)
self.assertTrue(overwrite_plan["ok"])
self.assertTrue(overwrite_plan["data"]["will_overwrite"])
self.assertNotIn(str(self.root), str(overwrite_plan["data"]))
execution = migrate_storage(
self.ctx,
{