From 0d3717fe140a766a4a2b9ca4055f400712b6d645 Mon Sep 17 00:00:00 2001 From: Isaac Tay Date: Fri, 25 Nov 2022 06:05:08 +0800 Subject: [PATCH] fix: made tool windows installations resilient against paths with whitespace (#228) * fix: fixed symlink code for windows * fix: fixed #227 with change to tool path Changes tool paths to use "& '\{tool_path}'\" so that they work on windows powershell when there are whitespaces in the directory path --- packages/perseus-cli/src/export.rs | 2 +- packages/perseus-cli/src/install.rs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/perseus-cli/src/export.rs b/packages/perseus-cli/src/export.rs index 4d8f17291c..0036ee1bf4 100644 --- a/packages/perseus-cli/src/export.rs +++ b/packages/perseus-cli/src/export.rs @@ -85,7 +85,7 @@ macro_rules! copy_directory { } } #[cfg(windows)] - if std::os::unix::fs::symlink_dir($target.join($from), $target.join($to_symlink)).is_err() { + if std::os::windows::fs::symlink_dir($target.join($from), $target.join($to_symlink)).is_err() { // That failed, try a usual copy if let Err(err) = fs_extra::dir::copy( $target.join($from), diff --git a/packages/perseus-cli/src/install.rs b/packages/perseus-cli/src/install.rs index f09350ffc1..1c5f026ea1 100644 --- a/packages/perseus-cli/src/install.rs +++ b/packages/perseus-cli/src/install.rs @@ -141,11 +141,15 @@ impl Tools { if let (ToolStatus::Available(wb_path), ToolStatus::Available(wo_path)) = (&wb_status, &wo_status) { + #[cfg(unix)] + let (wb_path, wo_path) = (wb_path.to_string(), wo_path.to_string()); + #[cfg(windows)] + let (wb_path, wo_path) = (format!("& \'{}\'", wb_path), format!("& \'{}\'", wo_path)); Ok(Tools { cargo_engine: global_opts.cargo_engine_path.clone(), cargo_browser: global_opts.cargo_browser_path.clone(), - wasm_bindgen: wb_path.to_string(), - wasm_opt: wo_path.to_string(), + wasm_bindgen: wb_path, + wasm_opt: wo_path, }) } else { // We need to install some things, which may take some time @@ -167,12 +171,16 @@ impl Tools { // If we're here, we have the paths succeed_spinner(&spinner, &spinner_msg); let paths = res.unwrap(); + #[cfg(unix)] + let (wb_path, wo_path) = paths; + #[cfg(windows)] + let (wb_path, wo_path) = (format!("& \'{}\'", paths.0), format!("& \'{}\'", paths.1)); Ok(Tools { cargo_engine: global_opts.cargo_engine_path.clone(), cargo_browser: global_opts.cargo_browser_path.clone(), - wasm_bindgen: paths.0, - wasm_opt: paths.1, + wasm_bindgen: wb_path, + wasm_opt: wo_path, }) } }