fix(desktop): skip distro probe for WSL drive paths
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user