From 9f1fa0a0a213d59401f33bb511f039f234293402 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Wed, 28 Oct 2026 15:15:13 +0100 Subject: [PATCH] launcher: quote server junction paths and show why mklink failed Creating a server on Windows failed with a bare "mklink /J failed" (#3200). servers.rs passed the paths to cmd unquoted, so a user folder with `&`, `^` or `(` broke cmd's parsing; sources.rs already quoted them. Both now use one sources::junction, which also puts cmd's own message in the error. Co-Authored-By: Claude Opus 5.5 --- launcher/src/servers.rs | 12 +----------- launcher/src/sources.rs | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/launcher/src/servers.rs b/launcher/src/servers.rs index 09961ce3b..df8a8357e 100644 --- a/launcher/src/servers.rs +++ b/launcher/src/servers.rs @@ -245,17 +245,7 @@ fn point(link: &Path, target: &Path) -> std::io::Result<()> { #[cfg(windows)] { let _ = fs::remove_dir(link); - let status = crate::process::command("cmd") - .args(["/C", "mklink", "/J"]) - .arg(link) - .arg(target) - .stdout(Stdio::null()) - .status()?; - if status.success() { - Ok(()) - } else { - Err(std::io::Error::other("mklink /J failed")) - } + crate::sources::junction(target, link) } } diff --git a/launcher/src/sources.rs b/launcher/src/sources.rs index 50953067e..4c188c3f7 100644 --- a/launcher/src/sources.rs +++ b/launcher/src/sources.rs @@ -498,6 +498,14 @@ fn make_link(target: &Path, link: &Path) -> std::io::Result<()> { if !target.is_dir() { return fs::hard_link(target, link).or_else(|_| fs::copy(target, link).map(|_| ())); } + junction(target, link) +} + +/// Makes `link` a junction to the folder `target` (no admin rights needed, unlike a symlink). The +/// error carries cmd's own message ("Access is denied", "The system cannot find the path…"). +#[cfg(windows)] +pub(crate) fn junction(target: &Path, link: &Path) -> std::io::Result<()> { + use std::os::windows::process::CommandExt; // Always quoted: cmd reads `&`, `^` or `(` in an unquoted path (a user folder may have // them) as its own syntax. A Windows path never holds a quote. let quoted = |path: &Path| { @@ -506,16 +514,19 @@ fn make_link(target: &Path, link: &Path) -> std::io::Result<()> { arg.push("\""); arg }; - let status = crate::process::command("cmd") + let out = crate::process::command("cmd") .args(["/C", "mklink", "/J"]) .raw_arg(quoted(link)) .raw_arg(quoted(target)) - .stdout(std::process::Stdio::null()) - .status()?; - match status.success() { - true => Ok(()), - false => Err(std::io::Error::other("mklink /J failed")), + .output()?; + if out.status.success() { + return Ok(()); } + let why = String::from_utf8_lossy(&out.stderr); + Err(std::io::Error::other(match why.trim() { + "" => "mklink /J failed".to_string(), + why => format!("mklink /J failed: {why}"), + })) } #[cfg(test)]