From b28dd42675ae4ef90f891b821cffe5cde45aaa79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Fri, 8 Mar 2024 15:43:06 +1100 Subject: [PATCH] feat: use CARGO_DIST_FORCE_INSTALL_DIR This ensures cargo-dist's installer will place this in the desired location, however it was configured before. We use this to make sure the new version absolutely goes in the same place as the old one. --- axoupdater/src/lib.rs | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/axoupdater/src/lib.rs b/axoupdater/src/lib.rs index b196244..8862029 100644 --- a/axoupdater/src/lib.rs +++ b/axoupdater/src/lib.rs @@ -189,12 +189,6 @@ impl AxoUpdater { /// system. /// Returns an error if the receipt hasn't been loaded yet. pub fn check_receipt_is_for_this_executable(&self) -> AxoupdateResult { - let Some(install_prefix) = &self.install_prefix else { - return Err(AxoupdateError::NotConfigured { - missing_field: "install_prefix".to_owned(), - }); - }; - let current_exe_path = Utf8PathBuf::from_path_buf(current_exe()?.canonicalize()?) .map_err(|path| AxoupdateError::CaminoConversionFailed { path })?; // First determine the parent dir @@ -210,16 +204,9 @@ impl AxoUpdater { } } - let mut install_root = install_prefix.to_owned(); - if install_root.file_name() == Some("bin") { - if let Some(parent) = install_root.parent() { - install_root = parent.to_path_buf(); - } - } - // Looks like this EXE comes from a different source than the install // receipt - if current_exe_root != install_root { + if current_exe_root != self.install_prefix_root()? { return Ok(false); } @@ -271,6 +258,27 @@ impl AxoUpdater { .block_on(self.is_update_needed()) } + /// Returns the root of the install prefix, stripping the final `/bin` + /// component if necessary. Works around a bug introduced in cargo-dist + /// where this field was returned inconsistently in receipts for a few + /// versions. + fn install_prefix_root(&self) -> AxoupdateResult { + let Some(install_prefix) = &self.install_prefix else { + return Err(AxoupdateError::NotConfigured { + missing_field: "install_prefix".to_owned(), + }); + }; + + let mut install_root = install_prefix.to_owned(); + if install_root.file_name() == Some("bin") { + if let Some(parent) = install_root.parent() { + install_root = parent.to_path_buf(); + } + } + + Ok(install_root) + } + /// Attempts to perform an update. The return value specifies whether an /// update was actually performed or not; false indicates "no update was /// needed", while an error indicates that an update couldn't be performed @@ -345,6 +353,9 @@ impl AxoUpdater { if !self.print_installer_stderr { command.stderr(Stdio::null()); } + // Forces the generated installer to install to exactly this path, + // regardless of how it's configured to install. + command.env("CARGO_DIST_FORCE_INSTALL_DIR", self.install_prefix_root()?); command.run()?; let result = UpdateResult {