Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(process): can't launch the app sometimes if the program path contains spaces #35

Merged
merged 5 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading