Skip to content

Commit 29b60a9

Browse files
fix(packager): rename main bin name for AppImage if it has spaces (#305)
* fix(packager): rename main bin name for AppImage if it has spaces ref tauri-apps/tauri#11218 * lint
1 parent e879b6c commit 29b60a9

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

.changes/appimage-spaces.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cargo-packager": patch
3+
---
4+
5+
Fix AppImage bundle when main binary name has spaces.

crates/packager/src/config/category.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ struct AppCategoryVisitor {
248248
did_you_mean: Option<&'static str>,
249249
}
250250

251-
impl<'d> serde::de::Visitor<'d> for AppCategoryVisitor {
251+
impl serde::de::Visitor<'_> for AppCategoryVisitor {
252252
type Value = AppCategory;
253253

254254
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {

crates/packager/src/config/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,14 @@ impl Config {
18201820
.ok_or_else(|| crate::Error::MainBinaryNotFound)
18211821
}
18221822

1823+
/// Returns a mutable reference to the main binary.
1824+
pub fn main_binary_mut(&mut self) -> crate::Result<&mut Binary> {
1825+
self.binaries
1826+
.iter_mut()
1827+
.find(|bin| bin.main)
1828+
.ok_or_else(|| crate::Error::MainBinaryNotFound)
1829+
}
1830+
18231831
/// Returns the main binary name.
18241832
pub fn main_binary_name(&self) -> crate::Result<String> {
18251833
self.binaries

crates/packager/src/package/appimage/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ pub(crate) fn package(ctx: &Context) -> crate::Result<Vec<PathBuf>> {
7272
..
7373
} = ctx;
7474

75+
let mut config = config.clone();
76+
let main_binary_name = config.main_binary_name()?;
77+
78+
// if binary file name contains spaces, we must change it to kebab-case
79+
if main_binary_name.contains(' ') {
80+
let main_binary = config.main_binary_mut()?;
81+
82+
let main_binary_name_kebab = heck::AsKebabCase(main_binary_name).to_string();
83+
let new_path = intermediates_path.join(&main_binary_name_kebab);
84+
fs::copy(&main_binary.path, &new_path)?;
85+
86+
main_binary.path = new_path;
87+
}
88+
7589
// generate the deb binary name
7690
let (arch, linuxdeploy_arch) = match config.target_arch()? {
7791
"x86" => ("i686", "i386"),
@@ -90,7 +104,7 @@ pub(crate) fn package(ctx: &Context) -> crate::Result<Vec<PathBuf>> {
90104

91105
// generate deb_folder structure
92106
tracing::debug!("Generating data");
93-
let icons = deb::generate_data(config, &appimage_deb_data_dir)?;
107+
let icons = deb::generate_data(&config, &appimage_deb_data_dir)?;
94108
tracing::debug!("Copying files specified in `appimage.files`");
95109
if let Some(files) = config.appimage().and_then(|d| d.files.as_ref()) {
96110
deb::copy_custom_files(files, &appimage_deb_data_dir)?;

0 commit comments

Comments
 (0)