Skip to content

Commit 31ab6f8

Browse files
fix(updater): preserve file extension of updater package (fix: #3283) (#3285)
* fix: preserve file extension of updated package (fix: #3283) Otherwise users may get confused when seing a sudo dialog which suggests a `rpm` package is installed using `dpkg -i` * pass on package extension more thoroughly * add changes file Update the updater package to preserve file extension, clarifying installation prompts for users. * Apply suggestion from @hrzlgnm * Apply suggestion from @hrzlgnm * Apply suggestion from @Legend-Master * More rpm and log `pkg_path` instead --------- Co-authored-by: Tony <68118705+Legend-Master@users.noreply.github.com> Co-authored-by: Tony <legendmastertony@gmail.com>
1 parent 21ae430 commit 31ab6f8

2 files changed

Lines changed: 24 additions & 13 deletions

File tree

.changes/change-pr-3285.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"updater": patch
3+
"updater-js": patch
4+
---
5+
6+
fix: preserve file extension of updater package, otherwise users may get confused when presented with a sudo dialog suggesting to install a file with the extension `.rpm` using `dpkg -i`

plugins/updater/src/updater.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ impl Update {
949949
}
950950
}
951951

952-
/// Linux (AppImage and Deb)
952+
/// Linux (AppImage, Deb, RPM)
953953
#[cfg(any(
954954
target_os = "linux",
955955
target_os = "dragonfly",
@@ -962,6 +962,7 @@ impl Update {
962962
/// ├── [AppName]_[version]_amd64.AppImage.tar.gz # GZ generated by tauri-bundler
963963
/// │ └──[AppName]_[version]_amd64.AppImage # Application AppImage
964964
/// ├── [AppName]_[version]_amd64.deb # Debian package
965+
/// ├── [AppName]_[version]_amd64.rpm # RPM package
965966
/// └── ...
966967
///
967968
fn install_inner(&self, bytes: &[u8]) -> Result<()> {
@@ -1052,18 +1053,24 @@ impl Update {
10521053
return Err(Error::InvalidUpdaterFormat);
10531054
}
10541055

1055-
self.try_tmp_locations(bytes, "dpkg", "-i")
1056+
self.try_tmp_locations(bytes, "dpkg", "-i", "deb")
10561057
}
10571058

10581059
fn install_rpm(&self, bytes: &[u8]) -> Result<()> {
10591060
// First verify the bytes are actually a .rpm package
10601061
if !infer::archive::is_rpm(bytes) {
10611062
return Err(Error::InvalidUpdaterFormat);
10621063
}
1063-
self.try_tmp_locations(bytes, "rpm", "-U")
1064+
self.try_tmp_locations(bytes, "rpm", "-U", "rpm")
10641065
}
10651066

1066-
fn try_tmp_locations(&self, bytes: &[u8], install_cmd: &str, install_arg: &str) -> Result<()> {
1067+
fn try_tmp_locations(
1068+
&self,
1069+
bytes: &[u8],
1070+
install_cmd: &str,
1071+
install_arg: &str,
1072+
package_extension: &str,
1073+
) -> Result<()> {
10671074
// Try different temp directories
10681075
let tmp_dir_locations = vec![
10691076
Box::new(|| Some(std::env::temp_dir())) as Box<dyn FnOnce() -> Option<PathBuf>>,
@@ -1074,13 +1081,11 @@ impl Update {
10741081
// Try writing to multiple temp locations until one succeeds
10751082
for tmp_dir_location in tmp_dir_locations {
10761083
if let Some(path) = tmp_dir_location() {
1077-
if let Ok(tmp_dir) = tempfile::Builder::new()
1078-
.prefix("tauri_rpm_update")
1079-
.tempdir_in(path)
1080-
{
1081-
let pkg_path = tmp_dir.path().join("package.rpm");
1084+
let prefix = format!("tauri_{package_extension}_update");
1085+
if let Ok(tmp_dir) = tempfile::Builder::new().prefix(&prefix).tempdir_in(path) {
1086+
let pkg_path = tmp_dir.path().join(format!("package.{package_extension}"));
10821087

1083-
// Try writing the .deb file
1088+
// Try writing the .deb / .rpm file
10841089
if std::fs::write(&pkg_path, bytes).is_ok() {
10851090
// If write succeeds, proceed with installation
10861091
return self.try_install_with_privileges(
@@ -1112,15 +1117,15 @@ impl Update {
11121117
.status()
11131118
{
11141119
if status.success() {
1115-
log::debug!("installed deb with pkexec");
1120+
log::debug!("installed {pkg_path:?} with pkexec");
11161121
return Ok(());
11171122
}
11181123
}
11191124

11201125
// 2. Try zenity or kdialog for a graphical sudo experience
11211126
if let Ok(password) = self.get_password_graphically() {
11221127
if self.install_with_sudo(pkg_path, &password, install_cmd, install_arg)? {
1123-
log::debug!("installed deb with GUI sudo");
1128+
log::debug!("installed {pkg_path:?} with GUI sudo");
11241129
return Ok(());
11251130
}
11261131
}
@@ -1133,7 +1138,7 @@ impl Update {
11331138
.status()?;
11341139

11351140
if status.success() {
1136-
log::debug!("installed deb with sudo");
1141+
log::debug!("installed {pkg_path:?} with sudo");
11371142
Ok(())
11381143
} else {
11391144
Err(Error::PackageInstallFailed)

0 commit comments

Comments
 (0)