From 3e084a68892cc417530afae3a0bc99d42128eca2 Mon Sep 17 00:00:00 2001 From: Earl Plak Date: Thu, 2 Apr 2026 13:57:18 +0200 Subject: [PATCH] fix: check POSIX absolute path before Win32 in resolveSymlinks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit path.win32.isAbsolute() returns true for POSIX absolute paths (a leading "/" is treated as the current drive root), so checking it first causes the root segment to be set to "" instead of "/". This produces a relative path, and realpath then resolves it against CWD — prepending the home directory on every iteration. Swapping the if/else-if order so path.posix.isAbsolute() is checked first fixes the duplicate path issue on Linux/macOS/WSL. Fixes #36 --- .../features/mcp-server-install/services/status.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/obsidian-plugin/src/features/mcp-server-install/services/status.ts b/packages/obsidian-plugin/src/features/mcp-server-install/services/status.ts index 0acfadca..956173c8 100644 --- a/packages/obsidian-plugin/src/features/mcp-server-install/services/status.ts +++ b/packages/obsidian-plugin/src/features/mcp-server-install/services/status.ts @@ -30,14 +30,19 @@ async function resolveSymlinks(filepath: string): Promise { let skipCount = 1; // Skip first segment by default // Handle the root segment differently for Windows vs POSIX - if (path.win32.isAbsolute(filepath)) { + // Check POSIX first: path.win32.isAbsolute() returns true for + // POSIX absolute paths (leading "/" is the current drive root in + // Win32), so checking it first would incorrectly push an empty + // string instead of "/" on Linux/macOS/WSL, producing a relative + // path that causes realpath to prepend CWD repeatedly. + if (path.posix.isAbsolute(filepath)) { + resolvedParts.push("/"); + } else if (path.win32.isAbsolute(filepath)) { resolvedParts.push(parts[0]); if (parts[1] === "") { resolvedParts.push(""); skipCount = 2; // Skip two segments for UNC paths } - } else if (path.posix.isAbsolute(filepath)) { - resolvedParts.push("/"); } else { resolvedParts.push(parts[0]); }