Skip to content

Commit

Permalink
fix(process): can't launch the app sometimes if the program path cont…
Browse files Browse the repository at this point in the history
…ains spaces (#35)
  • Loading branch information
Legend-Master authored Jul 3, 2024
1 parent 33aff8e commit 3cb9d91
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/fix-space-in-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"nsis_process": patch
"nsis_tauri_utils": patch
---

Fix can't launch the app sometimes if the program path contains spaces
28 changes: 27 additions & 1 deletion crates/nsis-process/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -337,6 +337,7 @@ impl DerefMut for OwnedHandle {

#[cfg(test)]
mod tests {

use super::*;

#[test]
Expand All @@ -357,4 +358,29 @@ mod tests {
fn spawn_cmd() {
unsafe { run_as_user("cmd", "/c timeout 3") };
}

#[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();

let systemroot = std::env::var("SYSTEMROOT").unwrap_or_else(|_| "C:\\Windows".to_owned());

let cmd = format!("{systemroot}\\System32\\cmd.exe");
let cmd_out = dir.join("cmdout.exe");

std::fs::copy(cmd, &cmd_out).unwrap();

assert!(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();
}
}

0 comments on commit 3cb9d91

Please sign in to comment.