fix(updater): fix appimage extraction (#784)

* fix updater on linux

* review changes

* Apply suggestions from code review

* change file

---------

Co-authored-by: Kris Krolak <krzysiek.krolak@gmail.com>
pull/797/head
kris-ava 2 years ago committed by GitHub
parent 2e2c0a1b95
commit e7c72c9816
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
"updater": patch
---
Fix updater failing to extract the AppImage resulting in failing to update and also deleting the current version.

@ -34,7 +34,7 @@ tar = "0.4"
[target."cfg(target_os = \"windows\")".dependencies]
zip = { version = "0.6", default-features = false }
[target."cfg(target_os = \"macos\")".dependencies]
[target."cfg(any(target_os = \"macos\", target_os = \"linux\"))".dependencies]
flate2 = "1.0.27"
[dev-dependencies]

@ -62,6 +62,8 @@ pub enum Error {
/// Temp dir is not on same mount mount. This prevents our updater to rename the AppImage to a temp file.
#[error("temp directory is not on the same mount point as the AppImage")]
TempDirNotOnSameMountPoint,
#[error("binary for the current target not found in the archive")]
BinaryNotFoundInAcrhive,
#[error(transparent)]
Http(#[from] http::Error),
}

@ -600,6 +600,7 @@ impl Update {
target_os = "openbsd"
))]
fn install_inner(&self, bytes: Vec<u8>) -> Result<()> {
use flate2::read::GzDecoder;
use std::{
ffi::OsStr,
os::unix::fs::{MetadataExt, PermissionsExt},
@ -632,7 +633,8 @@ impl Update {
// extract the buffer to the tmp_dir
// we extract our signed archive into our final directory without any temp file
let mut archive = tar::Archive::new(archive);
let decoder = GzDecoder::new(archive);
let mut archive = tar::Archive::new(decoder);
for mut entry in archive.entries()?.flatten() {
if let Ok(path) = entry.path() {
if path.extension() == Some(OsStr::new("AppImage")) {
@ -646,8 +648,10 @@ impl Update {
}
}
}
// if we have not returned early we should restore the backup
std::fs::rename(tmp_app_image, &self.extract_path)?;
return Ok(());
return Err(Error::BinaryNotFoundInAcrhive);
}
}
}

Loading…
Cancel
Save