Skip to content

Commit a49a19f

Browse files
fix(bundler): wrap Exec in desktop with quotes, rename appimage main binary if has spaces (#11218)
* fix(bundler): wrap `Exec` in desktop with quotes, rename appimage main binary if has spaces * Update .changes/main-binary-name-spaces-linux.md [skip ci[ --------- Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
1 parent 9102faa commit a49a19f

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-bundler": "patch:bug"
3+
"tauri-cli": "patch:bug"
4+
---
5+
6+
Fix bundling `appimage`, `deb` and `rpm` bundles failing to open when using `mainBinaryName` with spaces.

crates/tauri-bundler/src/bundle/linux/appimage/mod.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use anyhow::Context;
1515
use handlebars::Handlebars;
1616
use std::{
1717
collections::BTreeMap,
18-
fs::{remove_dir_all, write},
18+
fs,
1919
path::PathBuf,
2020
process::{Command, Stdio},
2121
};
@@ -38,17 +38,32 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
3838
};
3939
let package_dir = settings.project_out_directory().join("bundle/appimage_deb");
4040

41+
let main_binary = settings.main_binary()?;
42+
43+
let mut settings = settings.clone();
44+
if main_binary.name().contains(" ") {
45+
let main_binary_path = settings.binary_path(main_binary);
46+
let project_out_directory = settings.project_out_directory();
47+
48+
let main_binary_name_kebab = heck::AsKebabCase(main_binary.name()).to_string();
49+
let new_path = project_out_directory.join(&main_binary_name_kebab);
50+
fs::copy(main_binary_path, new_path)?;
51+
52+
let main_binary = settings.main_binary_mut()?;
53+
main_binary.set_name(main_binary_name_kebab);
54+
}
55+
4156
// generate deb_folder structure
42-
let (data_dir, icons) = debian::generate_data(settings, &package_dir)
57+
let (data_dir, icons) = debian::generate_data(&settings, &package_dir)
4358
.with_context(|| "Failed to build data folders and files")?;
4459
common::copy_custom_files(&settings.appimage().files, &data_dir)
4560
.with_context(|| "Failed to copy custom files")?;
4661

4762
let output_path = settings.project_out_directory().join("bundle/appimage");
4863
if output_path.exists() {
49-
remove_dir_all(&output_path)?;
64+
fs::remove_dir_all(&output_path)?;
5065
}
51-
std::fs::create_dir_all(output_path.clone())?;
66+
fs::create_dir_all(output_path.clone())?;
5267
let app_dir_path = output_path.join(format!("{}.AppDir", settings.product_name()));
5368
let appimage_filename = format!(
5469
"{}_{}_{}.AppImage",
@@ -101,7 +116,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
101116

102117
log::info!(action = "Bundling"; "{} ({})", appimage_filename, appimage_path.display());
103118

104-
write(&sh_file, temp)?;
119+
fs::write(&sh_file, temp)?;
105120

106121
// chmod script for execution
107122
Command::new("chmod")
@@ -119,6 +134,6 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
119134
.output_ok()
120135
.context("error running build_appimage.sh")?;
121136

122-
remove_dir_all(&package_dir)?;
137+
fs::remove_dir_all(&package_dir)?;
123138
Ok(vec![appimage_path])
124139
}

crates/tauri-bundler/src/bundle/linux/freedesktop/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub fn generate_desktop_file(
9999
data_dir: &Path,
100100
) -> crate::Result<(PathBuf, PathBuf)> {
101101
let bin_name = settings.main_binary_name()?;
102+
102103
let product_name = settings.product_name();
103104
let desktop_file_name = format!("{product_name}.desktop");
104105
let path = PathBuf::from("usr/share/applications").join(desktop_file_name);
@@ -150,6 +151,12 @@ pub fn generate_desktop_file(
150151

151152
let mime_type = (!mime_type.is_empty()).then_some(mime_type.join(";"));
152153

154+
let bin_name_exec = if bin_name.contains(" ") {
155+
format!("\"{bin_name}\"")
156+
} else {
157+
bin_name.to_string()
158+
};
159+
153160
handlebars.render_to_write(
154161
"main.desktop",
155162
&DesktopTemplateParams {
@@ -162,7 +169,7 @@ pub fn generate_desktop_file(
162169
} else {
163170
None
164171
},
165-
exec: bin_name,
172+
exec: &bin_name_exec,
166173
icon: bin_name,
167174
name: settings.product_name(),
168175
mime_type,

crates/tauri-bundler/src/bundle/settings.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,16 @@ impl Settings {
889889
.map_err(Into::into)
890890
}
891891

892+
/// Returns the file name of the binary being bundled.
893+
pub fn main_binary_mut(&mut self) -> crate::Result<&mut BundleBinary> {
894+
self
895+
.binaries
896+
.iter_mut()
897+
.find(|bin| bin.main)
898+
.context("failed to find main binary, make sure you have a `package > default-run` in the Cargo.toml file")
899+
.map_err(Into::into)
900+
}
901+
892902
/// Returns the file name of the binary being bundled.
893903
pub fn main_binary_name(&self) -> crate::Result<&str> {
894904
self

0 commit comments

Comments
 (0)