diff --git a/src/backend/mod.rs b/src/backend/mod.rs
index 8086962646..e8eb65968d 100644
--- a/src/backend/mod.rs
+++ b/src/backend/mod.rs
@@ -18,7 +18,9 @@ use crate::cmd::CmdLineRunner;
use crate::config::config_file::config_root;
use crate::config::{Config, Settings};
use crate::duration::parse_into_timestamp;
-use crate::file::{display_path, remove_all_with_progress, remove_all_with_warning};
+use crate::file::{
+ canonicalize_cached, display_path, remove_all_with_progress, remove_all_with_warning,
+};
use crate::install_before::resolve_before_date;
use crate::install_context::InstallContext;
use crate::lockfile::{PlatformInfo, ProvenanceType};
@@ -1346,21 +1348,16 @@ pub trait Backend: Debug + Send + Sync {
};
// Canonicalize to resolve any ".." components before checking.
// If target doesn't exist (canonicalize fails), don't skip - treat as needing install
- let Ok(target) = target.canonicalize() else {
- return None;
- };
+ let target = canonicalize_cached(&target)?;
// Canonicalize INSTALLS too for consistent comparison (handles symlinked data dirs)
- let installs = dirs::INSTALLS
- .canonicalize()
- .unwrap_or(dirs::INSTALLS.to_path_buf());
+ let installs =
+ canonicalize_cached(&dirs::INSTALLS).unwrap_or(dirs::INSTALLS.to_path_buf());
if target.starts_with(&installs) {
return Some(path);
}
// Also check shared install directories
for shared_dir in env::shared_install_dirs() {
- let shared = shared_dir
- .canonicalize()
- .unwrap_or(shared_dir.to_path_buf());
+ let shared = canonicalize_cached(&shared_dir).unwrap_or(shared_dir.to_path_buf());
if target.starts_with(&shared) {
return Some(path);
}
diff --git a/src/cli/activate.rs b/src/cli/activate.rs
index 8db9e763b6..6b2b6c0ff0 100644
--- a/src/cli/activate.rs
+++ b/src/cli/activate.rs
@@ -2,7 +2,7 @@ use std::path::{Path, PathBuf};
use crate::config::Settings;
use crate::env::PATH_KEY;
-use crate::file::touch_dir;
+use crate::file::{canonicalize_cached, canonicalize_or_self, touch_dir};
use crate::path_env::PathEnv;
use crate::shell::{ActivateOptions, ActivatePrelude, Shell, ShellType, get_shell};
use crate::toolset::env_cache::CachedEnv;
@@ -193,12 +193,10 @@ fn remove_shims() -> std::io::Result