Skip to content

Commit a68f5a8

Browse files
committed
fix: 安装 dsh fails on fresh bundled installs — strip \?\ verbatim prefix
Tauri's resource_dir() canonicalizes internally, returning \?\-prefixed verbatim paths on Windows. exists() accepts them, so resolution picks the bundled npm CLI at \?\D:\…\npm-cli.js — but Node v22's CJS resolver misreads the drive boundary in a verbatim path, walks past the filesystem root, and crashes in resolveMainPath with EISDIR: lstat 'D:' before npm even starts (nodejs/node#60435, upstream fix stalled). The user sees only 安装失败:npm 退出码 1 on a fresh bundled install. simplify() strips the prefix (dunce-style, keeping \?\UNC\ intact) at the source — every path handed to the bundled node is a plain Win32 path.
1 parent f57b7ae commit a68f5a8

1 file changed

Lines changed: 44 additions & 4 deletions

File tree

‎src-tauri/src/app/paths.rs‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ pub struct Paths {
3737

3838
impl Paths {
3939
pub fn resolve(app: &AppHandle) -> Self {
40-
let res = app.path().resource_dir().unwrap_or_default();
40+
let res = simplify(app.path().resource_dir().unwrap_or_default());
4141
let proj = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..");
42-
let user = app.path().app_data_dir().unwrap_or_else(|_| res.clone());
42+
let user = simplify(app.path().app_data_dir().unwrap_or_else(|_| res.clone()));
4343

4444
// Bundled Node binary name: node.exe on Windows, node elsewhere.
4545
let node_name = if cfg!(windows) { "node.exe" } else { "node" };
@@ -180,9 +180,9 @@ fn materialize_overlay(user: &Path) -> PathBuf {
180180
/// UI when the external flavor cannot find a global dsh, so a user can report
181181
/// exactly which probe failed instead of a bare 未找到全局 dsh.
182182
pub fn resolve_diagnostics(app: &AppHandle) -> String {
183-
let res = app.path().resource_dir().unwrap_or_default();
183+
let res = simplify(app.path().resource_dir().unwrap_or_default());
184184
let proj = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..");
185-
let user = app.path().app_data_dir().unwrap_or_else(|_| res.clone());
185+
let user = simplify(app.path().app_data_dir().unwrap_or_else(|_| res.clone()));
186186
let mut lines = Vec::new();
187187
lines.push(format!("resource_dir: {}", res.display()));
188188
lines.push(format!("app_data_dir: {}", user.display()));
@@ -220,6 +220,27 @@ pub fn resolve_diagnostics(app: &AppHandle) -> String {
220220
lines.join("\n")
221221
}
222222

223+
/// Strip the Windows verbatim prefix (`\\?\`) Tauri adds to
224+
/// `resource_dir` (it canonicalizes internally). Rust's `exists()` accepts
225+
/// the prefix, but Node's CJS resolver misreads the drive boundary in
226+
/// `\\?\D:\…`, walks past the filesystem root, and crashes with
227+
/// `EISDIR: lstat 'D:'` when such a path is passed as the script argument
228+
/// (nodejs/node#60435 — upstream fix stalled). Every path handed to the
229+
/// bundled node (npm CLI, dsh bin) must be a plain Win32 path.
230+
/// `\\?\UNC\server\share` is kept verbatim — stripping would corrupt it.
231+
fn simplify(path: PathBuf) -> PathBuf {
232+
#[cfg(windows)]
233+
{
234+
let text = path.as_os_str().to_string_lossy();
235+
if let Some(rest) = text.strip_prefix(r"\\?\") {
236+
if !rest.starts_with(r"UNC\") {
237+
return PathBuf::from(rest);
238+
}
239+
}
240+
}
241+
path
242+
}
243+
223244
/// Where the dsh runtime lives. Returns the dir that owns
224245
/// `node_modules/@deepseek-ai/dsh` plus whether the launcher manages it.
225246
/// `managed_only` = this install ships node+npm (bundled flavor) — only
@@ -375,6 +396,25 @@ mod tests {
375396
(dir.join("embedded-overlay.yml"), dir.join(".overlay-default"))
376397
}
377398

399+
#[test]
400+
fn verbatim_prefix_is_stripped() {
401+
// The bundled node crashes on \\?\-prefixed script paths (EISDIR).
402+
assert_eq!(
403+
super::simplify(PathBuf::from(r"\\?\D:\app\node.exe")),
404+
PathBuf::from(r"D:\app\node.exe")
405+
);
406+
// UNC shares must keep the prefix — stripping corrupts them.
407+
assert_eq!(
408+
super::simplify(PathBuf::from(r"\\?\UNC\server\share")),
409+
PathBuf::from(r"\\?\UNC\server\share")
410+
);
411+
// Plain paths pass through untouched.
412+
assert_eq!(
413+
super::simplify(PathBuf::from(r"C:\normal\path")),
414+
PathBuf::from(r"C:\normal\path")
415+
);
416+
}
417+
378418
#[test]
379419
fn overlay_missing_file_gets_default() {
380420
let user = temp_user_dir("missing");

0 commit comments

Comments
 (0)