pub fn validate_file_path(path: &Path) -> PatternsResult<PathBuf>Expand description
Validate and canonicalize a file path.
This function:
- Checks that the path exists
- Canonicalizes the path (resolves symlinks,
.,..) - Rejects system directories
- Validates UTF-8 encoding
§Arguments
path- The path to validate
§Returns
The canonicalized path if valid, or an error.
§Errors
PatternsError::FileNotFoundif the file doesn’t existPatternsError::PathTraversalif path is a system dir or has invalid encoding
§Example
ⓘ
let valid = validate_file_path(Path::new("src/main.py"))?;
assert!(valid.is_absolute());