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(packager): rename main bin name for AppImage if it has spaces #305

Merged
merged 2 commits into from
Feb 3, 2025
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
5 changes: 5 additions & 0 deletions .changes/appimage-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-packager": patch
---

Fix AppImage bundle when main binary name has spaces.
2 changes: 1 addition & 1 deletion crates/packager/src/config/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ struct AppCategoryVisitor {
did_you_mean: Option<&'static str>,
}

impl<'d> serde::de::Visitor<'d> for AppCategoryVisitor {
impl serde::de::Visitor<'_> for AppCategoryVisitor {
type Value = AppCategory;

fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
8 changes: 8 additions & 0 deletions crates/packager/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,14 @@ impl Config {
.ok_or_else(|| crate::Error::MainBinaryNotFound)
}

/// Returns a mutable reference to the main binary.
pub fn main_binary_mut(&mut self) -> crate::Result<&mut Binary> {
self.binaries
.iter_mut()
.find(|bin| bin.main)
.ok_or_else(|| crate::Error::MainBinaryNotFound)
}

/// Returns the main binary name.
pub fn main_binary_name(&self) -> crate::Result<String> {
self.binaries
Expand Down
16 changes: 15 additions & 1 deletion crates/packager/src/package/appimage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ pub(crate) fn package(ctx: &Context) -> crate::Result<Vec<PathBuf>> {
..
} = ctx;

let mut config = config.clone();
let main_binary_name = config.main_binary_name()?;

// if binary file name contains spaces, we must change it to kebab-case
if main_binary_name.contains(' ') {
let main_binary = config.main_binary_mut()?;

let main_binary_name_kebab = heck::AsKebabCase(main_binary_name).to_string();
let new_path = intermediates_path.join(&main_binary_name_kebab);
fs::copy(&main_binary.path, &new_path)?;

main_binary.path = new_path;
}

// generate the deb binary name
let (arch, linuxdeploy_arch) = match config.target_arch()? {
"x86" => ("i686", "i386"),
Expand All @@ -90,7 +104,7 @@ pub(crate) fn package(ctx: &Context) -> crate::Result<Vec<PathBuf>> {

// generate deb_folder structure
tracing::debug!("Generating data");
let icons = deb::generate_data(config, &appimage_deb_data_dir)?;
let icons = deb::generate_data(&config, &appimage_deb_data_dir)?;
tracing::debug!("Copying files specified in `appimage.files`");
if let Some(files) = config.appimage().and_then(|d| d.files.as_ref()) {
deb::copy_custom_files(files, &appimage_deb_data_dir)?;
Expand Down
Loading