Skip to content

Commit d865ed4

Browse files
authored
fix(shell): run sidecar with dots in filename, closes #2310 (#2950)
* fix(shell): run sidecar with dots in filename, closes #2310 * fix import * remove dead code * code review suggestions * clippy * clippy
1 parent 1107c46 commit d865ed4

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

.changes/fix-sidecar-dots.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"shell": patch
3+
"shell-js": patch
4+
---
5+
6+
Fix sidecar with dots in the filename not working on Windows.

plugins/shell/src/commands.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ fn prepare_cmd<R: Runtime>(
115115
let mut command = if options.sidecar {
116116
let program = PathBuf::from(program);
117117
let program_as_string = program.display().to_string();
118-
let program_no_ext_as_string = program.with_extension("").display().to_string();
118+
let has_extension = program.extension().is_some_and(|ext| ext == "exe");
119+
let program_no_ext_as_string = if has_extension {
120+
program.with_extension("").display().to_string()
121+
} else {
122+
program_as_string.clone()
123+
};
119124
let configured_sidecar = window
120125
.config()
121126
.bundle

plugins/shell/src/process/mod.rs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,23 @@ pub struct Output {
118118
fn relative_command_path(command: &Path) -> crate::Result<PathBuf> {
119119
match platform::current_exe()?.parent() {
120120
#[cfg(windows)]
121-
Some(exe_dir) => Ok(exe_dir.join(command).with_extension("exe")),
121+
Some(exe_dir) => {
122+
let mut command_path = exe_dir.join(command);
123+
let already_exe = command_path.extension().is_some_and(|ext| ext == "exe");
124+
if !already_exe {
125+
// do not use with_extension to retain dots in the command filename
126+
command_path.as_mut_os_string().push(".exe");
127+
}
128+
Ok(command_path)
129+
}
122130
#[cfg(not(windows))]
123-
Some(exe_dir) => Ok(exe_dir.join(command)),
131+
Some(exe_dir) => {
132+
let mut command_path = exe_dir.join(command);
133+
if command_path.extension().is_some_and(|ext| ext == "exe") {
134+
command_path.set_extension("");
135+
}
136+
Ok(command_path)
137+
}
124138
None => Err(crate::Error::CurrentExeHasNoParent),
125139
}
126140
}
@@ -133,6 +147,10 @@ impl From<Command> for StdCommand {
133147

134148
impl Command {
135149
pub(crate) fn new<S: AsRef<OsStr>>(program: S) -> Self {
150+
log::debug!(
151+
"Creating sidecar {}",
152+
program.as_ref().to_str().unwrap_or("")
153+
);
136154
let mut command = StdCommand::new(program);
137155

138156
command.stdout(Stdio::piped());
@@ -451,9 +469,33 @@ fn spawn_pipe_reader<F: Fn(Vec<u8>) -> CommandEvent + Send + Copy + 'static>(
451469
// tests for the commands functions.
452470
#[cfg(test)]
453471
mod tests {
454-
#[cfg(not(windows))]
455472
use super::*;
456473

474+
#[test]
475+
fn relative_command_path_resolves() {
476+
let cwd_parent = platform::current_exe()
477+
.unwrap()
478+
.parent()
479+
.unwrap()
480+
.to_owned();
481+
assert_eq!(
482+
relative_command_path(Path::new("Tauri.Example")).unwrap(),
483+
cwd_parent.join(if cfg!(windows) {
484+
"Tauri.Example.exe"
485+
} else {
486+
"Tauri.Example"
487+
})
488+
);
489+
assert_eq!(
490+
relative_command_path(Path::new("Tauri.Example.exe")).unwrap(),
491+
cwd_parent.join(if cfg!(windows) {
492+
"Tauri.Example.exe"
493+
} else {
494+
"Tauri.Example"
495+
})
496+
);
497+
}
498+
457499
#[cfg(not(windows))]
458500
#[test]
459501
fn test_cmd_spawn_output() {

0 commit comments

Comments
 (0)