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