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