diff --git a/core/storage.py b/core/storage.py index 32d55a9..bd89f3a 100644 --- a/core/storage.py +++ b/core/storage.py @@ -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, } diff --git a/tests/test_s2_routes.py b/tests/test_s2_routes.py index 1291e03..aab6d50 100644 --- a/tests/test_s2_routes.py +++ b/tests/test_s2_routes.py @@ -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, {