From 5a2ccffd413f08e816cc2b54a37a4092c1fe138d Mon Sep 17 00:00:00 2001 From: Xipong <217837358+Xipong@users.noreply.github.com> Date: Wed, 9 Sep 2026 01:20:01 +0300 Subject: [PATCH] fix(desktop): skip distro probe for WSL drive paths --- apps/desktop/electron/wsl-path-bridge.test.ts | 21 +++++++++++++------ apps/desktop/electron/wsl-path-bridge.ts | 12 +++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/apps/desktop/electron/wsl-path-bridge.test.ts b/apps/desktop/electron/wsl-path-bridge.test.ts index 52073af3c3..04ebf57267 100644 --- a/apps/desktop/electron/wsl-path-bridge.test.ts +++ b/apps/desktop/electron/wsl-path-bridge.test.ts @@ -39,13 +39,22 @@ test('parseDefaultDistro strips the default-marker and blank lines', () => { // ── wslPosixToWindowsAccessible ────────────────────────────────────── -test('wslPosixToWindowsAccessible maps a drvfs mount to its Windows drive', () => { - assert.equal(wslPosixToWindowsAccessible('/mnt/c/Users/alex', 'Ubuntu'), 'C:\\Users\\alex') - assert.equal(wslPosixToWindowsAccessible('/mnt/d', 'Ubuntu'), 'D:\\') -}) +test('wslPosixToWindowsAccessible resolves a distro only for paths that need a UNC share', () => { + let distroProbes = 0 -test('wslPosixToWindowsAccessible maps an in-distro POSIX path to a UNC share', () => { - assert.equal(wslPosixToWindowsAccessible('/home/alex/proj', 'Ubuntu'), '\\\\wsl.localhost\\Ubuntu\\home\\alex\\proj') + const resolveDistro = () => { + distroProbes += 1 + + return 'Ubuntu' + } + + assert.equal(wslPosixToWindowsAccessible('/mnt/c/Users/alex', undefined, resolveDistro), 'C:\\Users\\alex') + assert.equal(distroProbes, 0) + assert.equal( + wslPosixToWindowsAccessible('/home/alex/proj', undefined, resolveDistro), + '\\\\wsl.localhost\\Ubuntu\\home\\alex\\proj' + ) + assert.equal(distroProbes, 1) }) test('wslPosixToWindowsAccessible leaves non-absolute / already-Windows paths alone', () => { diff --git a/apps/desktop/electron/wsl-path-bridge.ts b/apps/desktop/electron/wsl-path-bridge.ts index feff32a2f7..cab863f742 100644 --- a/apps/desktop/electron/wsl-path-bridge.ts +++ b/apps/desktop/electron/wsl-path-bridge.ts @@ -133,7 +133,11 @@ function wslUncBase(distro: string): string { * (drvfs mount), any other absolute POSIX path → `\\wsl.localhost\\...`. * Non-absolute or already-Windows paths pass through. */ -export function wslPosixToWindowsAccessible(posixPath: string, distro: string = resolveDefaultWslDistro()): string { +export function wslPosixToWindowsAccessible( + posixPath: string, + distro?: string, + resolveDistro: () => string = resolveDefaultWslDistro +): string { const value = String(posixPath || '').trim() const normalized = value.replace(/\\/g, '/') @@ -151,7 +155,7 @@ export function wslPosixToWindowsAccessible(posixPath: string, distro: string = const relative = normalized.replace(/^\/+/, '').replace(/\//g, '\\') - return `${wslUncBase(distro)}\\${relative}` + return `${wslUncBase(distro ?? resolveDistro())}\\${relative}` } /** Native folder dialog `defaultPath`: open a WSL cwd in the Windows picker. */ @@ -174,7 +178,7 @@ export function resolvePickerDefaultPath( const value = String(defaultPath).trim() return value.startsWith('/') && !WIN_DRIVE_RE.test(value) - ? wslPosixToWindowsAccessible(value, distro ?? resolveDefaultWslDistro()) + ? wslPosixToWindowsAccessible(value, distro) : defaultPath } @@ -191,6 +195,6 @@ export function resolveLocalReadPath(dirPath: string, distro?: string, profile?: } return IS_WINDOWS && value.startsWith('/') && !WIN_DRIVE_RE.test(value) - ? wslPosixToWindowsAccessible(value, distro ?? resolveDefaultWslDistro()) + ? wslPosixToWindowsAccessible(value, distro) : value }