Peach: Local-first video metadata scraper and media manager.
fix(tooling): tolerate CloudDrive empty-folder cleanup
longmeidao96382b54a25c
diff --git a/scripts/rehome_unknown_jav.py b/scripts/rehome_unknown_jav.pyindex b72a92acc..457425ff3 100644--- a/scripts/rehome_unknown_jav.py+++ b/scripts/rehome_unknown_jav.py@@ -224,10 +224,18 @@ def _remove_empty_tree(root: Path) -> None:directories = sorted((path for path in root.rglob("*") if path.is_dir()),key=lambda path: len(path.parts), reverse=True)for directory in directories:- if not any(directory.iterdir()):- directory.rmdir()- if root.is_dir() and not any(root.iterdir()):- root.rmdir()+ try:+ if not any(directory.iterdir()):+ directory.rmdir()+ except FileNotFoundError:+ # CloudDrive 会在最后一个文件移走后自行收掉某些空目录;+ # 计划中的旧句柄随即失效,这等价于已完成清理。+ continue+ try:+ if root.is_dir() and not any(root.iterdir()):+ root.rmdir()+ except FileNotFoundError:+ passdef apply_plan(diff --git a/tests/test_scripts.py b/tests/test_scripts.pyindex f19214c7a..18d899af8 100644--- a/tests/test_scripts.py+++ b/tests/test_scripts.py@@ -402,6 +402,23 @@ class OperationalScriptTests(unittest.TestCase):self.assertTrue((unknown / "ABP-340" / "one" / "ABP-340.mp4").is_file())self.assertFalse((root / "番号" / "Prestige" / "ABP-340").exists())+ def test_rehome_unknown_jav_accepts_cloud_drive_removing_an_empty_layer(self):+ with tempfile.TemporaryDirectory() as tmp:+ root = Path(tmp) / "code"+ vanished = root / "release title"+ vanished.mkdir(parents=True)+ original_iterdir = Path.iterdir++ def cloud_drive_iterdir(path):+ if path == vanished and path.exists():+ path.rmdir()+ raise FileNotFoundError(path)+ return original_iterdir(path)++ with mock.patch.object(Path, "iterdir", cloud_drive_iterdir):+ self.rehome_unknown._remove_empty_tree(root)+ self.assertFalse(root.exists())+def test_media_batch_scripts_are_import_safe_and_keep_context_rules(self):self.assertEqual(self.probe.context_fields(1920, 1080, 180), ("速食", "横屏", "2K"))with tempfile.TemporaryDirectory() as tmp: