Normalize a path for lookup (resolve . and .., remove trailing slashes) Performs case-folding on case-insensitive platforms (Windows/macOS) to match real FS behavior.
(path: &'a Path)
| 78 | /// |
| 79 | /// Performs case-folding on case-insensitive platforms (Windows/macOS) to match real FS behavior. |
| 80 | pub fn normalize_path<'a>(path: &'a Path) -> std::borrow::Cow<'a, Path> { |
| 81 | let normalized = normalize_path_structural(path); |
| 82 | |
| 83 | let needs_case_fold = cfg!(any(target_os = "windows", target_os = "macos")) |
| 84 | && normalized |
| 85 | .to_str() |
| 86 | .map(|s| s.chars().any(|c| c.is_uppercase())) |
| 87 | .unwrap_or(true); |
| 88 | |
| 89 | if !needs_case_fold { |
| 90 | return normalized; |
| 91 | } |
| 92 | |
| 93 | let path_str = normalized.to_string_lossy().to_lowercase(); |
| 94 | std::borrow::Cow::Owned(PathBuf::from(path_str)) |
| 95 | } |
| 96 | |
| 97 | pub fn normalize_path_structural<'a>(path: &'a Path) -> std::borrow::Cow<'a, Path> { |
| 98 | // Fast path: check if normalization is needed |
no test coverage detected