From 8d120c7585022e6ad7d7ca97b45d88dd582f934a Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 23 Jul 2024 22:09:36 +0800 Subject: [PATCH 1/2] fix(dmg): canonicalize path returns from `create_icns_file` --- .changes/fix-dmg-failed-with-out-dir.md | 5 +++++ crates/packager/src/util.rs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changes/fix-dmg-failed-with-out-dir.md diff --git a/.changes/fix-dmg-failed-with-out-dir.md b/.changes/fix-dmg-failed-with-out-dir.md new file mode 100644 index 00000000..fe468983 --- /dev/null +++ b/.changes/fix-dmg-failed-with-out-dir.md @@ -0,0 +1,5 @@ +--- +"cargo-packager": patch +--- + +Fixed dmg failed to bundle the application when out-dir does not exist. diff --git a/crates/packager/src/util.rs b/crates/packager/src/util.rs index fa3f9bc8..6e130a0f 100644 --- a/crates/packager/src/util.rs +++ b/crates/packager/src/util.rs @@ -315,7 +315,7 @@ pub fn create_icns_file(out_dir: &Path, config: &crate::Config) -> crate::Result ); std::fs::copy(&icon_path, &dest_path)?; - return Ok(Some(dest_path)); + return Ok(Some(dunce::canonicalize(dest_path)?)); } } } @@ -379,7 +379,7 @@ pub fn create_icns_file(out_dir: &Path, config: &crate::Config) -> crate::Result dest_path.set_extension("icns"); let icns_file = std::io::BufWriter::new(File::create(&dest_path)?); family.write(icns_file)?; - Ok(Some(dest_path)) + Ok(Some(dunce::canonicalize(dest_path)?)) } else { Err(crate::Error::InvalidIconList) } From af6cd387b3fb80539ef8f88c4882d1928849b6ad Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 16 Aug 2024 14:36:39 +0800 Subject: [PATCH 2/2] fix: canonicalize `out_dir` --- crates/packager/src/config/mod.rs | 10 +++++----- crates/packager/src/util.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/packager/src/config/mod.rs b/crates/packager/src/config/mod.rs index aea68e04..64651319 100644 --- a/crates/packager/src/config/mod.rs +++ b/crates/packager/src/config/mod.rs @@ -1792,13 +1792,13 @@ impl Config { /// Returns the out dir. Defaults to the current directory. pub fn out_dir(&self) -> PathBuf { if self.out_dir.as_os_str().is_empty() { - std::env::current_dir().expect("failed to resolve cwd") - } else if self.out_dir.exists() { - dunce::canonicalize(&self.out_dir).unwrap_or_else(|_| self.out_dir.clone()) - } else { + return std::env::current_dir().expect("failed to resolve cwd"); + } + + if !self.out_dir.exists() { std::fs::create_dir_all(&self.out_dir).expect("failed to create output directory"); - self.out_dir.clone() } + dunce::canonicalize(&self.out_dir).unwrap_or_else(|_| self.out_dir.clone()) } /// Returns the binaries dir. Defaults to [`Self::out_dir`] if [`Self::binaries_dir`] is not set. diff --git a/crates/packager/src/util.rs b/crates/packager/src/util.rs index 6e130a0f..fa3f9bc8 100644 --- a/crates/packager/src/util.rs +++ b/crates/packager/src/util.rs @@ -315,7 +315,7 @@ pub fn create_icns_file(out_dir: &Path, config: &crate::Config) -> crate::Result ); std::fs::copy(&icon_path, &dest_path)?; - return Ok(Some(dunce::canonicalize(dest_path)?)); + return Ok(Some(dest_path)); } } } @@ -379,7 +379,7 @@ pub fn create_icns_file(out_dir: &Path, config: &crate::Config) -> crate::Result dest_path.set_extension("icns"); let icns_file = std::io::BufWriter::new(File::create(&dest_path)?); family.write(icns_file)?; - Ok(Some(dunce::canonicalize(dest_path)?)) + Ok(Some(dest_path)) } else { Err(crate::Error::InvalidIconList) }