From aafc1719e904cab8594d71c1c0bb4312246e19d2 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 2 Jul 2024 21:46:51 +0800 Subject: [PATCH 1/5] Wrap program in quotes --- .changes/fix-space-in-path.md | 5 +++++ crates/nsis-process/src/lib.rs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-space-in-path.md diff --git a/.changes/fix-space-in-path.md b/.changes/fix-space-in-path.md new file mode 100644 index 0000000..5a5ae8e --- /dev/null +++ b/.changes/fix-space-in-path.md @@ -0,0 +1,5 @@ +--- +"nsis-tauri-utils": patch +--- + +Fix can't launch the app sometimes if the program path contains spaces diff --git a/crates/nsis-process/src/lib.rs b/crates/nsis-process/src/lib.rs index 51e9ba2..519a0ae 100644 --- a/crates/nsis-process/src/lib.rs +++ b/crates/nsis-process/src/lib.rs @@ -274,7 +274,7 @@ unsafe fn run_as_user(program: &str, arguments: &str) -> bool { lpAttributeList: attribute_list, }; let mut process_info: PROCESS_INFORMATION = mem::zeroed(); - let mut command_line = program.to_owned(); + let mut command_line = "\"".to_owned() + program + "\""; if !arguments.is_empty() { command_line.push(' '); command_line.push_str(arguments); From 841143da4fc4ebabf07295037adca2e03c9ddf08 Mon Sep 17 00:00:00 2001 From: Tony Date: Tue, 2 Jul 2024 21:56:52 +0800 Subject: [PATCH 2/5] Fix change file crate names --- .changes/fix-space-in-path.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.changes/fix-space-in-path.md b/.changes/fix-space-in-path.md index 5a5ae8e..488a10f 100644 --- a/.changes/fix-space-in-path.md +++ b/.changes/fix-space-in-path.md @@ -1,5 +1,6 @@ --- -"nsis-tauri-utils": patch +"nsis_process": patch +"nsis_tauri_utils": patch --- Fix can't launch the app sometimes if the program path contains spaces From ddde984302f0c93732b47dc2f50e626d2cdc3b2f Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 3 Jul 2024 05:05:11 +0300 Subject: [PATCH 3/5] add test --- crates/nsis-process/src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/nsis-process/src/lib.rs b/crates/nsis-process/src/lib.rs index 519a0ae..f7fd2a8 100644 --- a/crates/nsis-process/src/lib.rs +++ b/crates/nsis-process/src/lib.rs @@ -357,4 +357,21 @@ mod tests { fn spawn_cmd() { unsafe { run_as_user("cmd", "/c timeout 3") }; } + + #[test] + fn spawn_with_spaces() { + let current = std::env::current_dir().unwrap(); + + let dir = current.join("dir space"); + std::fs::create_dir_all(dir).unwrap(); + + let systemroot = std::env::var("SYSTEMROOT").unwrap_or("C:\\Windows"); + + let cmd = format!("{systemroot}\\System32\\cmd.exe"); + let cmd_out = dir.join("cmdout.exe"); + + std::fs::copy(cmd, cmd_out).unwrap(); + + unsafe { run_as_user(cmd_out.display().to_string().as_str(), "/c timeout 3") }; + } } From 1333d743f7ba583b1324b0cef4571b2945be03e5 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 3 Jul 2024 05:07:57 +0300 Subject: [PATCH 4/5] fmt --- crates/nsis-process/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/nsis-process/src/lib.rs b/crates/nsis-process/src/lib.rs index f7fd2a8..89afb04 100644 --- a/crates/nsis-process/src/lib.rs +++ b/crates/nsis-process/src/lib.rs @@ -361,17 +361,17 @@ mod tests { #[test] fn spawn_with_spaces() { let current = std::env::current_dir().unwrap(); - + let dir = current.join("dir space"); std::fs::create_dir_all(dir).unwrap(); let systemroot = std::env::var("SYSTEMROOT").unwrap_or("C:\\Windows"); - + let cmd = format!("{systemroot}\\System32\\cmd.exe"); let cmd_out = dir.join("cmdout.exe"); - + std::fs::copy(cmd, cmd_out).unwrap(); - + unsafe { run_as_user(cmd_out.display().to_string().as_str(), "/c timeout 3") }; } } From 2eaf041914ccfe098014b1dd361f99687653d678 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Wed, 3 Jul 2024 05:17:15 +0300 Subject: [PATCH 5/5] fix test --- crates/nsis-process/src/lib.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/crates/nsis-process/src/lib.rs b/crates/nsis-process/src/lib.rs index 89afb04..6293519 100644 --- a/crates/nsis-process/src/lib.rs +++ b/crates/nsis-process/src/lib.rs @@ -337,6 +337,7 @@ impl DerefMut for OwnedHandle { #[cfg(test)] mod tests { + use super::*; #[test] @@ -359,19 +360,27 @@ mod tests { } #[test] + #[cfg(feature = "test")] fn spawn_with_spaces() { + extern crate std; + use alloc::format; + use alloc::string::ToString; + let current = std::env::current_dir().unwrap(); let dir = current.join("dir space"); - std::fs::create_dir_all(dir).unwrap(); + std::fs::create_dir_all(&dir).unwrap(); + + let systemroot = std::env::var("SYSTEMROOT").unwrap_or_else(|_| "C:\\Windows".to_owned()); - let systemroot = std::env::var("SYSTEMROOT").unwrap_or("C:\\Windows"); + let cmd = format!("{systemroot}\\System32\\cmd.exe"); + let cmd_out = dir.join("cmdout.exe"); - let cmd = format!("{systemroot}\\System32\\cmd.exe"); - let cmd_out = dir.join("cmdout.exe"); + std::fs::copy(cmd, &cmd_out).unwrap(); - std::fs::copy(cmd, cmd_out).unwrap(); + assert!(unsafe { run_as_user(cmd_out.display().to_string().as_str(), "/c timeout 3") }); - unsafe { run_as_user(cmd_out.display().to_string().as_str(), "/c timeout 3") }; + std::thread::sleep(std::time::Duration::from_secs(5)); + std::fs::remove_file(cmd_out).unwrap(); } }