From 3f0428eeacecda49c027de5dd444ae3140740834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Misty=20De=20M=C3=A9o?= Date: Wed, 11 Sep 2024 11:59:53 -0700 Subject: [PATCH] fix: handle canonicalizing dead path If the receipt points to a path that no longer exists, the call to canonicalize will blow up. In that case, we can fall back to the original path as listed in the receipt for safety. --- axoupdater/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/axoupdater/src/lib.rs b/axoupdater/src/lib.rs index 6ac7ae1..a8d55fb 100644 --- a/axoupdater/src/lib.rs +++ b/axoupdater/src/lib.rs @@ -365,7 +365,16 @@ impl AxoUpdater { /// Returns a normalized version of install_prefix_root, for comparison fn install_prefix_root_normalized(&self) -> AxoupdateResult { let raw_root = self.install_prefix_root()?; - let normalized = Utf8PathBuf::from_path_buf(raw_root.canonicalize()?) + // The canonicalize path could fail if the path doesn't exist anymore; + // catch that specific error here and return the original path. + // (We want to leave the UTF8 conversion to the next step so we handle + // those errors separately.) + let canonicalized = if let Ok(path) = raw_root.canonicalize() { + path + } else { + raw_root.into_std_path_buf() + }; + let normalized = Utf8PathBuf::from_path_buf(canonicalized) .map_err(|path| AxoupdateError::CaminoConversionFailed { path })?; Ok(normalized) }