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