Peach: Local-first video metadata scraper and media manager.
perf(media): Windows 账本路径只做 abspath,不再 resolve
longmeidaof1f49229644a
diff --git a/src/peach/media.py b/src/peach/media.pyindex db184e3bc..baaf82250 100644--- a/src/peach/media.py+++ b/src/peach/media.py@@ -20,11 +20,17 @@ from .segments import HLS_SEGMENT_SECONDSdef normalized_path(path: Path | str) -> Path:- """Windows 离线/云盘可能让 realpath 失败;仍保留绝对路径安全边界。+ """账本路径翻译成本机可开的绝对路径,越界判断以它为准。- 账本里的盘符路径先按本机挂载点翻译,macOS 上才不会被当成当前目录下的相对路径。+ Windows 只做 `abspath`,不做 `resolve()`:PikPak 的 A: 是 WinFsp 映射的网络驱动器,+ `resolve()` 会逐级向重定向器问最终路径,一条文件路径要 7 秒,得到的还是+ `\\\\CloudDrive-…\\Pikpak\\…` 这种 UNC 形态,之后每次 stat 或 open 再各花 7 到 14 秒,+ 而同一个文件走盘符只要 1 毫秒。盘符路径本身就是绝对路径,`..` 由 `abspath` 折掉。+ macOS 仍要 `resolve()`:`/var` 是 `/private/var` 的软链,挂载点的大小写也靠它对齐。"""candidate = translate_ledger_path(path)+ if os.name == "nt":+ return Path(os.path.abspath(os.fspath(candidate)))try:return candidate.resolve()except OSError:diff --git a/tests/test_media.py b/tests/test_media.pyindex de268d878..0937f2bb0 100644--- a/tests/test_media.py+++ b/tests/test_media.py@@ -85,6 +85,14 @@ class MediaEngineTests(unittest.TestCase):path = normalized_path(Path("B:/"))self.assertTrue(path.is_absolute())+ @unittest.skipUnless(os.name == "nt", "只有 Windows 的盘符路径跳过 resolve")+ def test_windows_ledger_paths_are_not_resolved_through_the_redirector(self):+ """PikPak 的 A: 是 WinFsp 网络驱动器:`resolve()` 一条文件路径要 7 秒,还换成 UNC 形态,+ 之后每次 stat 再花 7 到 14 秒;盘符路径本身就是绝对路径,只需要折掉 `..`。"""+ with patch.object(Path, "resolve", side_effect=AssertionError("resolve() 走了网络重定向器")):+ path = normalized_path(r"A:\番号\..\番号\clip.mp4")+ self.assertEqual(path, Path(r"A:\番号\clip.mp4"))+def test_filesystem_backend_matches_case_insensitively_on_sensitive_mounts(self):"""CloudDrive 大小写敏感:账本 `abw-118.mp4` 对磁盘 `ABW-118.mp4` 必须救回。"""with tempfile.TemporaryDirectory() as tmp: