fix(desktop): skip distro probe for WSL drive paths

This commit is contained in:
Xipong
2026-09-09 01:20:01 +03:00
committed by Teknium
parent ef677265d2
commit 5a2ccffd41
2 changed files with 23 additions and 10 deletions
+15 -6
View File
@@ -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', () => {
+8 -4
View File
@@ -133,7 +133,11 @@ function wslUncBase(distro: string): string {
* (drvfs mount), any other absolute POSIX path → `\\wsl.localhost\<distro>\...`.
* 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
}