pub fn normalize_path(path: &Path) -> PathBufExpand description
Normalizes a path by resolving . and .. components.
This function cleans up path components by:
- Removing
.(current directory) components - Resolving
..(parent directory) components - Maintaining the path’s absolute or relative nature
Note: This function performs logical path resolution without accessing the filesystem. It does not resolve symbolic links or verify that the path exists.
§Arguments
path- The path to normalize
§Returns
A normalized PathBuf with . and .. components resolved
§Examples
use agpm_cli::utils::fs::normalize_path;
use std::path::{Path, PathBuf};
let path = Path::new("/foo/./bar/../baz");
let normalized = normalize_path(path);
assert_eq!(normalized, PathBuf::from("/foo/baz"));
let relative = Path::new("../src/./lib.rs");
let normalized_rel = normalize_path(relative);
assert_eq!(normalized_rel, PathBuf::from("../src/lib.rs"));§Use Cases
- Cleaning user input paths
- Path comparison and deduplication
- Security checks for path traversal
- Canonical path representation
§See Also
is_safe_pathfor security validation using this normalizationsafe_canonicalizefor filesystem-aware path resolution