use std::io;
use std::path::{Path, PathBuf};
pub(super) trait PathNormalizer {
fn normalize(&self, path: &Path) -> io::Result<PathBuf>;
}
#[derive(Debug, Default, Clone, Copy)]
pub(super) struct FsPathNormalizer;
impl PathNormalizer for FsPathNormalizer {
fn normalize(&self, path: &Path) -> io::Result<PathBuf> {
std::fs::canonicalize(path)
}
}
pub(super) fn normalized_path_key(
normalizer: &impl PathNormalizer,
path: &str,
) -> io::Result<PathBuf> {
normalizer.normalize(Path::new(path))
}
#[cfg(test)]
#[derive(Debug, Default, Clone, Copy)]
pub(super) struct FailingPathNormalizer;
#[cfg(test)]
impl PathNormalizer for FailingPathNormalizer {
fn normalize(&self, _path: &Path) -> io::Result<PathBuf> {
Err(io::Error::new(
io::ErrorKind::PermissionDenied,
"normalization refused for test",
))
}
}