fix: canonicalize missing managed paths

This commit is contained in:
luckyyzh
2026-07-31 03:28:46 +08:00
parent 6c2f88e44a
commit 32496d24a2
+6 -2
View File
@@ -1,5 +1,5 @@
import { existsSync, realpathSync } from "fs"; import { existsSync, realpathSync } from "fs";
import { isAbsolute, relative, resolve, sep } from "path"; import { basename, dirname, isAbsolute, relative, resolve, sep } from "path";
import { import {
SettingsManager, SettingsManager,
type ResourceDiagnostic, type ResourceDiagnostic,
@@ -64,7 +64,11 @@ export function getManagedRuntimePaths(): ManagedRuntimePaths {
function canonicalPath(path: string): string { function canonicalPath(path: string): string {
const resolved = resolve(path); const resolved = resolve(path);
if (!existsSync(resolved)) return resolved; if (!existsSync(resolved)) {
const parent = dirname(resolved);
if (parent === resolved) return resolved;
return resolve(canonicalPath(parent), basename(resolved));
}
try { try {
return realpathSync.native(resolved); return realpathSync.native(resolved);
} catch { } catch {