Skip to main content

validate_file_path

Function validate_file_path 

Source
pub fn validate_file_path(path: &Path) -> ContractsResult<PathBuf>
Expand description

Validate and canonicalize a file path.

This function:

  1. Checks that the path exists
  2. Canonicalizes the path (resolves symlinks, ., ..)
  3. Rejects paths that escape the project root (if specified)
  4. Rejects system directories
  5. Validates UTF-8 encoding

§Arguments

  • path - The path to validate

§Returns

The canonicalized path if valid, or an error.

§Errors

  • ContractsError::FileNotFound if the file doesn’t exist
  • ContractsError::PathTraversal if path escapes project or is a system dir

§Example

let valid = validate_file_path(Path::new("src/main.rs"))?;
assert!(valid.is_absolute());