diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index a7be96c943..ab406b898c 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -69,10 +69,12 @@ ide-extension = { path = "../crates/ide-extension" } ide-docker = { path = "../crates/ide-docker" } ide-android = { path = "../crates/ide-android" } +# The RPM update package is written to a private temporary folder before `pkexec rpm` installs it. +tempfile.workspace = true + [dev-dependencies] # The updater's version order (tauri-plugin-updater compares with semver). semver = "1" -tempfile.workspace = true [[test]] name = "background_tab_appkit" diff --git a/src-tauri/src/commands/window.rs b/src-tauri/src/commands/window.rs index 2e743bd393..ecbaf3177f 100644 --- a/src-tauri/src/commands/window.rs +++ b/src-tauri/src/commands/window.rs @@ -883,7 +883,13 @@ pub async fn app_install_update( let exe = tauri::utils::platform::current_exe()?; return ide_tools::portable_update::install(&exe, &bytes); } - update.install(bytes).map_err(|e| IdeError::internal(e.to_string())) + if crate::updates::installs_rpm(std::env::consts::OS, tauri::utils::platform::bundle_type()) { + return crate::updates::install_rpm(&bytes); + } + update.install(bytes).map_err(|e| { + tracing::error!(target = %update.target, error = %e, "update install failed"); + IdeError::internal(e.to_string()) + }) }) .await .map_err(|e| IdeError::internal(e.to_string()))?; diff --git a/src-tauri/src/updates.rs b/src-tauri/src/updates.rs index 0129d39803..16c18f977f 100644 --- a/src-tauri/src/updates.rs +++ b/src-tauri/src/updates.rs @@ -25,6 +25,41 @@ pub(crate) struct DownloadedUpdate { pub path: PathBuf, } +/// Whether this build installs its updates as an `.rpm`, through [`install_rpm`] rather than the plugin. +/// +/// The plugin's own `rpm -U` fails on RPM 6 (Fedora 43+), which refuses packages without an OpenPGP +/// signature, and the release RPMs carry none. +pub fn installs_rpm(os: &str, bundle: Option) -> bool { + os == "linux" && bundle == Some(tauri::utils::config::BundleType::Rpm) +} + +/// The `pkexec` arguments that install `package`. The package has passed the updater's minisign +/// check (`verify_file`) and rpm still checks the payload digests; drop `--nosignature` once CI +/// signs the RPMs with `rpmsign --addsign`. +pub fn rpm_install_args(package: &Path) -> Vec { + ["rpm", "-U", "--nosignature"].map(Into::into).into_iter().chain([package.into()]).collect() +} + +/// Installs the verified `bytes` with `pkexec rpm`, keeping rpm's own message in the error and the +/// log. They go to a new file in a private temporary folder rather than being read again from the +/// download cache, so what rpm installs as root is what the signature check saw. +pub fn install_rpm(bytes: &[u8]) -> IdeResult<()> { + let dir = tempfile::Builder::new().prefix("openidea-update-").tempdir()?; + let package = dir.path().join("update.rpm"); + std::fs::write(&package, bytes)?; + let output = std::process::Command::new("pkexec") + .args(rpm_install_args(&package)) + .output() + .map_err(|error| IdeError::unavailable(format!("cannot run pkexec: {error}")))?; + if output.status.success() { + return Ok(()); + } + let text = String::from_utf8_lossy(&output.stderr); + let message = format!("rpm update failed ({}): {}", output.status, text.trim()); + tracing::error!("{message}"); + Err(IdeError::internal(message)) +} + /// Tauri patches the installer copies; the raw exe shipped in the portable zip keeps no bundle type. pub fn portable_target(os: &str, arch: &str, bundle: Option) -> Option { (os == "windows" && bundle.is_none()).then(|| format!("windows-{arch}-portable")) @@ -292,6 +327,18 @@ fn ready_owner(preferred: Option<&str>, live: &[String], ready: &HashSet mod tests { use super::*; + #[test] + fn rpm_installs_on_linux_skip_the_signature_check_only() { + use tauri::utils::config::BundleType; + let args = rpm_install_args(Path::new("/tmp/openidea-update-x/update.rpm")); + assert_eq!(args, ["rpm", "-U", "--nosignature", "/tmp/openidea-update-x/update.rpm"]); + assert!(installs_rpm("linux", Some(BundleType::Rpm))); + assert!(!installs_rpm("linux", Some(BundleType::Deb))); + assert!(!installs_rpm("linux", Some(BundleType::AppImage))); + assert!(!installs_rpm("linux", None)); + assert!(!installs_rpm("macos", Some(BundleType::Rpm))); + } + #[test] fn only_unbundled_windows_builds_select_portable_updates() { use tauri::utils::config::BundleType;