fix(updater): installation on macos #591

pull/592/head
pashokitsme 2 years ago
parent 70e535abd5
commit 0a0eb3861b
No known key found for this signature in database
GPG Key ID: 7313CAC65D77DACD

@ -32,6 +32,10 @@ tar = "0.4"
[target."cfg(target_os = \"windows\")".dependencies] [target."cfg(target_os = \"windows\")".dependencies]
zip = { version = "0.6", default-features = false } zip = { version = "0.6", default-features = false }
[target."cfg(target_os = \"macos\")".dependencies]
flate2 = "1.0.27"
[dev-dependencies] [dev-dependencies]
mockito = "0.31" mockito = "0.31"

@ -657,7 +657,9 @@ impl Update {
// └── ... // └── ...
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn install_inner(&self, bytes: Vec<u8>) -> Result<()> { fn install_inner(&self, bytes: Vec<u8>) -> Result<()> {
let archive = Cursor::new(bytes); use flate2::read::GzDecoder;
let cursor = Cursor::new(bytes);
let mut extracted_files: Vec<PathBuf> = Vec::new(); let mut extracted_files: Vec<PathBuf> = Vec::new();
// the first file in the tar.gz will always be // the first file in the tar.gz will always be
@ -669,16 +671,22 @@ impl Update {
// create backup of our current app // create backup of our current app
std::fs::rename(&self.extract_path, tmp_dir.path())?; std::fs::rename(&self.extract_path, tmp_dir.path())?;
let mut archive = tar::Archive::new(archive); let decoder = GzDecoder::new(cursor);
for mut entry in archive.entries()?.flatten() { let mut archive = tar::Archive::new(decoder);
if let Ok(path) = entry.path() {
std::fs::create_dir(&self.extract_path)?;
extracted_files.push(self.extract_path.clone());
for entry in archive.entries()? {
let mut entry = entry?;
// skip the first folder (should be the app name) // skip the first folder (should be the app name)
let collected_path: PathBuf = path.iter().skip(1).collect(); let collected_path: PathBuf = entry.path()?.iter().skip(1).collect();
let extraction_path = &self.extract_path.join(collected_path); let extraction_path = &self.extract_path.join(collected_path);
// if something went wrong during the extraction, we should restore previous app // if something went wrong during the extraction, we should restore previous app
if let Err(err) = entry.unpack(extraction_path) { if let Err(err) = entry.unpack(extraction_path) {
for file in &extracted_files { for file in extracted_files.iter().rev() {
// delete all the files we extracted // delete all the files we extracted
if file.is_dir() { if file.is_dir() {
std::fs::remove_dir(file)?; std::fs::remove_dir(file)?;
@ -692,7 +700,6 @@ impl Update {
extracted_files.push(extraction_path.to_path_buf()); extracted_files.push(extraction_path.to_path_buf());
} }
}
let _ = std::process::Command::new("touch") let _ = std::process::Command::new("touch")
.arg(&self.extract_path) .arg(&self.extract_path)

Loading…
Cancel
Save