From 337e23eb7818f9c995cbda3a90caca379a081d5c Mon Sep 17 00:00:00 2001 From: jLynx Date: Wed, 13 Nov 2024 11:13:00 +1300 Subject: [PATCH] refactor --- plugins/updater/src/error.rs | 2 ++ plugins/updater/src/updater.rs | 33 +++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/plugins/updater/src/error.rs b/plugins/updater/src/error.rs index 5f6b7d8f..d6d9b0ce 100644 --- a/plugins/updater/src/error.rs +++ b/plugins/updater/src/error.rs @@ -63,6 +63,8 @@ pub enum Error { TempDirNotOnSameMountPoint, #[error("binary for the current target not found in the archive")] BinaryNotFoundInArchive, + #[error("failed to create temporary directory")] + TempDirNotFound, #[error("Authentication failed or was cancelled")] AuthenticationFailed, #[error("Failed to install .deb package")] diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index 64288b44..9e4f0fed 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -765,14 +765,14 @@ impl Update { /// fn install_inner(&self, bytes: &[u8]) -> Result<()> { if self.is_deb_package() { - self.install_deb_update(bytes) + self.install_deb(bytes) } else { // Handle AppImage or other formats - self.install_appimage_update(bytes) + self.install_appimage(bytes) } } - fn install_appimage_update(&self, bytes: &[u8]) -> Result<()> { + fn install_appimage(&self, bytes: &[u8]) -> Result<()> { use std::os::unix::fs::{MetadataExt, PermissionsExt}; let extract_path_metadata = self.extract_path.metadata()?; @@ -876,23 +876,28 @@ impl Update { dpkg_exists && apt_exists && package_in_dpkg } - fn install_deb_update(&self, bytes: &[u8]) -> Result<()> { - // Create a temporary directory - let tmp_dir = tempfile::Builder::new() - .prefix("tauri_deb_update") - .tempdir_in("/tmp")?; - + fn install_deb(&self, bytes: &[u8]) -> Result<()> { + // Try different temp directories, similar to AppImage handling + let tmp_dir_locations = ["/tmp", "/var/tmp", "/dev/shm"]; + + let tmp_dir = tmp_dir_locations + .iter() + .find_map(|dir| { + tempfile::Builder::new() + .prefix("tauri_deb_update") + .tempdir_in(dir) + .ok() + }) + .ok_or_else(|| Error::TempDirNotFound)?; + let deb_path = tmp_dir.path().join("package.deb"); - + // Direct .deb file std::fs::write(&deb_path, bytes)?; - + // Try different privilege escalation methods let installation_result = self.try_install_with_privileges(&deb_path); - // Clean up - let _ = std::fs::remove_file(&deb_path); - installation_result }