From 21441f30c5a258b73926ba7a7d8126d6bf47a662 Mon Sep 17 00:00:00 2001 From: Jason Tsai Date: Wed, 21 Aug 2024 21:43:04 +0800 Subject: [PATCH] fix(dmg): canonicalize path returns from `create_icns_file` (#262) * fix(dmg): canonicalize path returns from `create_icns_file` * fix: canonicalize `out_dir` --- .changes/fix-dmg-failed-with-out-dir.md | 5 +++++ crates/packager/src/config/mod.rs | 10 +++++----- 2 files changed, 10 insertions(+), 5 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/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.