Skip to content

Commit

Permalink
filename -> path
Browse files Browse the repository at this point in the history
  • Loading branch information
amr-crabnebula committed Nov 17, 2023
1 parent fc39d54 commit 4b12689
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
45 changes: 27 additions & 18 deletions crates/updater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn FnOnce() -> Option<PathBuf>>,
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(());
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/updater/tests/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn build_app(cwd: &Path, root_dir: &Path, version: &str, target: &[UpdaterFormat
&target.iter().map(|t|t.name()).collect::<Vec<_>>().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
Expand Down
2 changes: 1 addition & 1 deletion examples/wails/Packager.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 4b12689

Please sign in to comment.