Skip to content

Commit

Permalink
fix(updater): installation on macos #591 (#592)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <lucas@tauri.app>
fix(updater): installation on macos #591
fix(updater): use zip flate2 feature #591
fix(updater): use zip flate2 feature #591"
  • Loading branch information
pashokitsme and lucasfernog authored Oct 19, 2023
1 parent d1b7c2c commit 0e642e6
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-updater-macos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"updater": patch
---

Fixes update on macOS.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions plugins/updater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ tar = "0.4"
[target."cfg(target_os = \"windows\")".dependencies]
zip = { version = "0.6", default-features = false }

[target."cfg(target_os = \"macos\")".dependencies]
flate2 = "1.0.27"


[dev-dependencies]
mockito = "0.31"

Expand Down
48 changes: 27 additions & 21 deletions plugins/updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,9 @@ impl Update {
// └── ...
#[cfg(target_os = "macos")]
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();

// the first file in the tar.gz will always be
Expand All @@ -673,29 +675,33 @@ impl Update {
// create backup of our current app
std::fs::rename(&self.extract_path, tmp_dir.path())?;

let mut archive = tar::Archive::new(archive);
for mut entry in archive.entries()?.flatten() {
if let Ok(path) = entry.path() {
// skip the first folder (should be the app name)
let collected_path: PathBuf = path.iter().skip(1).collect();
let extraction_path = &self.extract_path.join(collected_path);

// if something went wrong during the extraction, we should restore previous app
if let Err(err) = entry.unpack(extraction_path) {
for file in &extracted_files {
// delete all the files we extracted
if file.is_dir() {
std::fs::remove_dir(file)?;
} else {
std::fs::remove_file(file)?;
}
let decoder = GzDecoder::new(cursor);
let mut archive = tar::Archive::new(decoder);

std::fs::create_dir(&self.extract_path)?;

for entry in archive.entries()? {
let mut entry = entry?;

// skip the first folder (should be the app name)
let collected_path: PathBuf = entry.path()?.iter().skip(1).collect();
let extraction_path = &self.extract_path.join(collected_path);

// if something went wrong during the extraction, we should restore previous app
if let Err(err) = entry.unpack(extraction_path) {
for file in extracted_files.iter().rev() {
// delete all the files we extracted
if file.is_dir() {
std::fs::remove_dir(file)?;
} else {
std::fs::remove_file(file)?;
}
std::fs::rename(tmp_dir.path(), &self.extract_path)?;
return Err(err.into());
}

extracted_files.push(extraction_path.to_path_buf());
std::fs::rename(tmp_dir.path(), &self.extract_path)?;
return Err(err.into());
}

extracted_files.push(extraction_path.to_path_buf());
}

let _ = std::process::Command::new("touch")
Expand Down
2 changes: 1 addition & 1 deletion plugins/updater/tests/app-updater/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"updater": {
"active": true,
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDE5QzMxNjYwNTM5OEUwNTgKUldSWTRKaFRZQmJER1h4d1ZMYVA3dnluSjdpN2RmMldJR09hUFFlZDY0SlFqckkvRUJhZDJVZXAK",
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEMwNjY1MEExMTFBMDU5RTUKUldUbFdhQVJvVkJtd09sZ1ROT25yVGFhU2o0ZnUyd1FlT0ZTQ2ZXamN3SXk4SjZLZmNwRnV5dTMK",
"windows": {
"installMode": "quiet"
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/updater/tests/app-updater/tests/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{

use serde::Serialize;

const UPDATER_PRIVATE_KEY: &str = "dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5YTBGV3JiTy9lRDZVd3NkL0RoQ1htZmExNDd3RmJaNmRMT1ZGVjczWTBKZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQWdMekUzVkE4K0tWQ1hjeGt1Vkx2QnRUR3pzQjVuV0ZpM2czWXNkRm9hVUxrVnB6TUN3K1NheHJMREhQbUVWVFZRK3NIL1VsMDBHNW5ET1EzQno0UStSb21nRW4vZlpTaXIwZFh5ZmRlL1lSN0dKcHdyOUVPclVvdzFhVkxDVnZrbHM2T1o4Tk1NWEU9Cg==";
const UPDATER_PRIVATE_KEY: &str = "dW50cnVzdGVkIGNvbW1lbnQ6IHJzaWduIGVuY3J5cHRlZCBzZWNyZXQga2V5ClJXUlRZMEl5Qm9uUXIyeEM2YkczeGMwZDFENmw1WHEzaFk5aDlOOXNyTWRxRnY4UUpzZ0FBQkFBQUFBQUFBQUFBQUlBQUFBQTVWbWdFYUZRWnNDZmdyUW9ibWExVEFTY0pVTWpVS2xlOHdhR1I3Q3hpd2FTNjg1MXZENEQyZWxnVE5PbnJUYWFTajRmdTJ3UWVPRlNDZldqY3dJeThKNktmY3BGdXl1M1BPdHgwOFhIQzJLSnpqS0Z2cVdmaEs2WWRmK3d4SHVCMlpHVGduaVAzclU9Cg==";

#[derive(Serialize)]
struct PackageConfig {
Expand Down Expand Up @@ -72,8 +72,8 @@ fn build_app(cwd: &Path, config: &Config, bundle_updater: bool, target: BundleTa
command.args(["--bundles", "msi", "nsis"]);

command
.env("TAURI_PRIVATE_KEY", UPDATER_PRIVATE_KEY)
.env("TAURI_KEY_PASSWORD", "")
.env("TAURI_SIGNING_PRIVATE_KEY", UPDATER_PRIVATE_KEY)
.env("TAURI_SIGNING_PRIVATE_KEY_PASSWORD", "")
.args(["--bundles", "updater"]);
} else {
#[cfg(windows)]
Expand Down

0 comments on commit 0e642e6

Please sign in to comment.