Replies: 1 comment
|
已对照 master 源码锚点(
explorer.exe 替换方向有三个实现坑(直接照搬
另注意 修复面在 native-command(host 原语,非插件可挂载层)→ upstream-fix 候选;你的 patch 方向正确,把 explorer 退出码坑一并纳入即可直接提交讨论区供维护者拾取。 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
问题描述
DSH 运行在 WSL2 中时,通过 host.openPath / host.openTextFile 打开位于 WSL Linux 文件系统中的文件会失败。
不限文件类型,.md、.txt 等均可复现。
当前调用链大致为:
openWslPath
-> wslpath -w
-> openWindowsPath
-> powershell.exe
-> Invoke-Item -LiteralPath "\wsl.localhost<distro>..."
最终返回:
path open failed
Invoke-Item : Element not found
CategoryInfo : NotSpecified: (:) [Invoke-Item], Win32Exception
FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.InvokeItemCommand
与已有 WSL / PATH 问题的区别
我的 WSL 配置中设置了:
appendWindowsPath=false
但本机通过一个受控的 local shim 显式提供了 powershell.exe,因此 powershell.exe 可以正常解析并启动。
所以这与类似 spawn powershell.exe ENOENT 的问题不同:失败发生在 PowerShell 已成功启动之后。
已确认的现象
wslpath -w 生成的 Windows 路径本身有效,例如:
\wsl.localhost<distro>\home...\foo.md
对同一路径:
我也测试了:
cmd /c start
rundll32 url.dll,FileProtocolHandler
file:// URL
均无法解决此问题。
因此看起来并不是 WSL 文件路径不可访问,而是 Invoke-Item 所走的 Windows shell open 路径无法正确处理该 WSL UNC namespace。
一个可工作的修复方向
对 WSL 路径,在 wslpath -w 后不要再进入 PowerShell Invoke-Item,而是直接交给 Explorer:
await run(explorerPath, [windowsPath], signal);
即:
Linux path
-> wslpath -w
-> \wsl.localhost<distro>...
-> explorer.exe
-> Windows 默认关联程序
建议仅修改 openWslPath 的行为,保留普通 Windows 路径现有的 Invoke-Item 实现。
另一个小点是,不建议依赖 bare explorer.exe 一定存在于 WSL $PATH 中,因为 appendWindowsPath=false 是合法配置。可以显式解析 Windows Explorer 的位置,或采用其他不依赖 Windows PATH 注入的方式。
现有 internals.run seam 应该也比较方便加入 regression test,验证 WSL opener 最终调用的 executable 和 argv。
Caveat
通过 explorer.exe handoff 后,Explorer 很快返回,并且某些后续打开失败不会反馈给调用方。
对于“使用默认应用打开”这种桌面 gesture,我认为可以接受把成功语义定义为:
已成功将打开请求交给 host desktop,而不是保证目标应用最终成功渲染文件。
⸻
English summary
This appears to be distinct from the existing powershell.exe discovery / appendWindowsPath=false issue.
In my environment, appendWindowsPath=false is enabled, but powershell.exe is deliberately exposed through a local shim and launches successfully. The failure happens afterwards.
wslpath -w produces a valid \wsl.localhost<distro>... path. Test-Path and Get-Item succeed on it, while Invoke-Item -LiteralPath fails with ELEMENT_NOT_FOUND. The same path works when passed directly to explorer.exe, which launches the associated Windows application and opens the file correctly.
A possible fix is therefore to special-case WSL paths:
openWslPath
-> wslpath -w
-> explorer.exe
while leaving the native Windows Invoke-Item opener unchanged.
It would also be preferable not to assume that Windows executables are globally present in the WSL $PATH, since appendWindowsPath=false is a valid configuration.
All reactions