Resolve the OS problems

This commit is contained in:
Omar Abdulla
2025-08-15 09:57:05 +03:00
parent 59e50973d4
commit 64d0a7f995
6 changed files with 126 additions and 55 deletions
+24
View File
@@ -47,3 +47,27 @@ pub fn read_dir(path: impl AsRef<Path>) -> Result<Box<dyn Iterator<Item = Result
}
}
}
pub trait PathExt {
fn cached_canonicalize(&self) -> Result<PathBuf>;
}
impl<T> PathExt for T
where
T: AsRef<Path>,
{
fn cached_canonicalize(&self) -> Result<PathBuf> {
static CANONICALIZATION_CACHE: Lazy<Cache<PathBuf, PathBuf>> =
Lazy::new(|| Cache::new(10_000));
let path = self.as_ref().to_path_buf();
match CANONICALIZATION_CACHE.get(&path) {
Some(canonicalized) => Ok(canonicalized),
None => {
let canonicalized = path.canonicalize()?;
CANONICALIZATION_CACHE.insert(path, canonicalized.clone());
Ok(canonicalized)
}
}
}
}