diff --git a/.changes/fix-updater-macos.md b/.changes/fix-updater-macos.md new file mode 100644 index 000000000..c4f4d8311 --- /dev/null +++ b/.changes/fix-updater-macos.md @@ -0,0 +1,5 @@ +--- +"updater": patch +--- + +Fixes update on macOS. diff --git a/Cargo.lock b/Cargo.lock index ab7ad828a..4768943ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1688,9 +1688,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "miniz_oxide", @@ -5997,6 +5997,7 @@ version = "2.0.0-alpha.2" dependencies = [ "base64 0.21.2", "dirs-next", + "flate2", "futures-util", "http", "minisign-verify", diff --git a/plugins/updater/Cargo.toml b/plugins/updater/Cargo.toml index 6088df91b..9764f7718 100644 --- a/plugins/updater/Cargo.toml +++ b/plugins/updater/Cargo.toml @@ -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" diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index 225c3857f..4a6b352ab 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -661,7 +661,9 @@ impl Update { // └── ... #[cfg(target_os = "macos")] fn install_inner(&self, bytes: Vec) -> Result<()> { - let archive = Cursor::new(bytes); + use flate2::read::GzDecoder; + + let cursor = Cursor::new(bytes); let mut extracted_files: Vec = Vec::new(); // the first file in the tar.gz will always be @@ -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") diff --git a/plugins/updater/tests/app-updater/tauri.conf.json b/plugins/updater/tests/app-updater/tauri.conf.json index 440dd8569..86dc5a768 100644 --- a/plugins/updater/tests/app-updater/tauri.conf.json +++ b/plugins/updater/tests/app-updater/tauri.conf.json @@ -24,7 +24,7 @@ }, "updater": { "active": true, - "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDE5QzMxNjYwNTM5OEUwNTgKUldSWTRKaFRZQmJER1h4d1ZMYVA3dnluSjdpN2RmMldJR09hUFFlZDY0SlFqckkvRUJhZDJVZXAK", + "pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IEMwNjY1MEExMTFBMDU5RTUKUldUbFdhQVJvVkJtd09sZ1ROT25yVGFhU2o0ZnUyd1FlT0ZTQ2ZXamN3SXk4SjZLZmNwRnV5dTMK", "windows": { "installMode": "quiet" } diff --git a/plugins/updater/tests/app-updater/tests/update.rs b/plugins/updater/tests/app-updater/tests/update.rs index d6be25083..287664e87 100644 --- a/plugins/updater/tests/app-updater/tests/update.rs +++ b/plugins/updater/tests/app-updater/tests/update.rs @@ -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 { @@ -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)]