Mountain/Cache/PathCanon/Canonicalize.rs
1//! Canonicalise via the cache. Returns the cached entry on hit; runs
2//! `dunce::canonicalize` on miss and caches the result.
3//!
4//! `dunce::canonicalize` is preferred over `std::fs::canonicalize` because it
5//! avoids the `\\?\` UNC prefix on Windows; the underlying syscall on
6//! macOS/Linux is identical (`realpath(3)`).
7
8use std::path::{Path, PathBuf};
9
10use crate::Cache::PathCanon::Cache::CACHE;
11
12pub fn Fn(Path:&Path) -> std::io::Result<PathBuf> {
13 if let Some(Hit) = CACHE.get(Path) {
14 return Ok(Hit);
15 }
16
17 let Resolved = dunce::canonicalize(Path)?;
18
19 CACHE.insert(Path.to_path_buf(), Resolved.clone());
20
21 Ok(Resolved)
22}