Skip to content

Commit

Permalink
fix: handle canonicalizing dead path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mistydemeo committed Sep 11, 2024
1 parent a548d60 commit 3f0428e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion axoupdater/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,16 @@ impl AxoUpdater {
/// Returns a normalized version of install_prefix_root, for comparison
fn install_prefix_root_normalized(&self) -> AxoupdateResult<Utf8PathBuf> {
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)
}
Expand Down

0 comments on commit 3f0428e

Please sign in to comment.