From 4b1268915a538808def23957fd6defb97bf5c440 Mon Sep 17 00:00:00 2001 From: amr-crabnebula Date: Fri, 17 Nov 2023 03:42:54 +0200 Subject: [PATCH] filename -> path --- crates/updater/src/lib.rs | 45 ++++++++++++++++++++-------------- crates/updater/tests/update.rs | 2 +- examples/wails/Packager.toml | 2 +- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/crates/updater/src/lib.rs b/crates/updater/src/lib.rs index 8dcba266..928dc17c 100644 --- a/crates/updater/src/lib.rs +++ b/crates/updater/src/lib.rs @@ -663,33 +663,42 @@ impl Update { _ => return Err(crate::Error::UnsupportedUpdateFormat), }; + let extract_path_metadata = self.extract_path.metadata()?; let tmp_dir_locations = vec![ Box::new(|| Some(std::env::temp_dir())) as Box Option>, Box::new(dirs::cache_dir), Box::new(|| Some(self.extract_path.parent().unwrap().to_path_buf())), ]; + dbg!(&self.extract_path); for tmp_dir_location in tmp_dir_locations { - if let Some(tmp_dir_location) = tmp_dir_location() { - let (_, tmp_app_image) = tempfile::Builder::new() - .prefix("current_app") - .suffix(".AppImage") - .tempfile_in(tmp_dir_location)? - .keep()?; - - // create a backup of our current app image - if let Err(_) = std::fs::rename(&self.extract_path, &tmp_app_image) { - continue; - } + if let Some(tmp_dir) = tmp_dir_location() { + use std::os::unix::fs::{MetadataExt, PermissionsExt}; + + let tmp_dir_metadata = tmp_dir.metadata()?; + if extract_path_metadata.dev() == tmp_dir_metadata.dev() { + let mut perms = tmp_dir_metadata.permissions(); + perms.set_mode(0o700); + std::fs::set_permissions(&tmp_dir, perms)?; + + let (_, tmp_app_image) = tempfile::Builder::new() + .prefix("current_app") + .suffix(".AppImage") + .tempfile_in(tmp_dir)? + .keep()?; + + // create a backup of our current app image + std::fs::rename(&self.extract_path, &tmp_app_image)?; + + // if something went wrong during the extraction, we should restore previous app + if let Err(err) = std::fs::write(&self.extract_path, bytes) { + std::fs::rename(tmp_app_image, &self.extract_path)?; + return Err(err.into()); + } - // if something went wrong during the extraction, we should restore previous app - if let Err(err) = std::fs::write(&self.extract_path, bytes) { - std::fs::rename(tmp_app_image, &self.extract_path)?; - return Err(err.into()); + // early finish we have everything we need here + return Ok(()); } - - // early finish we have everything we need here - return Ok(()); } } diff --git a/crates/updater/tests/update.rs b/crates/updater/tests/update.rs index 79b9cde7..0d9af175 100644 --- a/crates/updater/tests/update.rs +++ b/crates/updater/tests/update.rs @@ -43,7 +43,7 @@ fn build_app(cwd: &Path, root_dir: &Path, version: &str, target: &[UpdaterFormat &target.iter().map(|t|t.name()).collect::>().join(","), "-c", ]) - .arg(format!(r#"{{"outDir":"{}","beforePackagingCommand": "cargo build", "identifier": "com.updater-app.test", "productName": "CargoPackagerAppUpdaterTest", "version": "{version}", "icons": ["32x32.png"], "binaries": [{{"filename": "cargo-packager-updater-app-test", "main": true}}]}}"#, root_dir.join("target/debug").to_string_lossy().replace("\\\\?\\", "").replace('\\', "\\\\"))) + .arg(format!(r#"{{"outDir":"{}","beforePackagingCommand": "cargo build", "identifier": "com.updater-app.test", "productName": "CargoPackagerAppUpdaterTest", "version": "{version}", "icons": ["32x32.png"], "binaries": [{{"path": "cargo-packager-updater-app-test", "main": true}}]}}"#, root_dir.join("target/debug").to_string_lossy().replace("\\\\?\\", "").replace('\\', "\\\\"))) .env("CARGO_PACKAGER_SIGN_PRIVATE_KEY", UPDATER_PRIVATE_KEY) .env("CARGO_PACKAGER_SIGN_PRIVATE_KEY_PASSWORD", "") // This is read by the updater app test diff --git a/examples/wails/Packager.toml b/examples/wails/Packager.toml index 80be6aaa..21749e20 100644 --- a/examples/wails/Packager.toml +++ b/examples/wails/Packager.toml @@ -6,7 +6,7 @@ product-name = "Wails example" identifier = "com.wails.example" resources = ["Cargo.toml", "src", "32x32.png"] icons = ["32x32.png"] -binaries = [{ filename = "wails_example", main = true }] +binaries = [{ path = "wails_example", main = true }] [deb] depends = ["libgtk-3-0", "libwebkit2gtk-4.1-0"]