Skip to content

Commit

Permalink
fix(updater): panic when updating with empty current_exe_args (tauri-…
Browse files Browse the repository at this point in the history
  • Loading branch information
talzion12 committed Feb 17, 2025
1 parent a7497b0 commit 8d905d3
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions plugins/updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@ impl UpdaterBuilder {
on_before_exit: self.on_before_exit,
})
}
}

impl UpdaterBuilder {
pub(crate) fn current_exe_args<I, S>(mut self, args: I) -> Self
where
I: IntoIterator<Item = S>,
Expand Down Expand Up @@ -618,7 +616,13 @@ impl Update {
let updater_type = self.extract(bytes)?;

let install_mode = self.config.install_mode();
let current_args = &self.current_exe_args()[1..];
let current_exe_args = self.current_exe_args();
let current_args =
current_exe_args
.split_first()
.map(|(_, args_without_exe)| args_without_exe)
.unwrap_or(&[]);

let msi_args;

let installer_args: Vec<&OsStr> = match &updater_type {
Expand All @@ -627,25 +631,35 @@ impl Update {
.iter()
.map(OsStr::new)
.chain(once(OsStr::new("/UPDATE")))
.chain(once(OsStr::new("/ARGS")))
.chain(current_args.to_vec())
.chain(
if current_args.len() > 0 {
Some(once(OsStr::new("/ARGS")).chain(current_args.iter().map(|arg| *arg)))
} else {
None
}.into_iter().flatten()
)
.chain(self.installer_args())
.collect(),
WindowsUpdaterType::Msi { path, .. } => {
let escaped_args = current_args
.iter()
.map(escape_msi_property_arg)
.collect::<Vec<_>>()
.join(" ");
msi_args = OsString::from(format!("LAUNCHAPPARGS=\"{escaped_args}\""));
if current_args.len() > 0 {
let escaped_args = current_args
.iter()
.map(escape_msi_property_arg)
.collect::<Vec<_>>()
.join(" ");
msi_args = Some(OsString::from(format!("LAUNCHAPPARGS=\"{escaped_args}\"")));
}
else {
msi_args = None;
}

[OsStr::new("/i"), path.as_os_str()]
.into_iter()
.chain(install_mode.msiexec_args().iter().map(OsStr::new))
.chain(once(OsStr::new("/promptrestart")))
.chain(self.installer_args())
.chain(once(OsStr::new("AUTOLAUNCHAPP=True")))
.chain(once(msi_args.as_os_str()))
.chain(msi_args.iter().map(|args| args.as_os_str()))
.collect()
}
};
Expand Down

0 comments on commit 8d905d3

Please sign in to comment.