Skip to main content

validate_file_path

Function validate_file_path 

Source
pub fn validate_file_path(path: &Path) -> PatternsResult<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 system directories
  4. Validates UTF-8 encoding

§Arguments

  • path - The path to validate

§Returns

The canonicalized path if valid, or an error.

§Errors

  • PatternsError::FileNotFound if the file doesn’t exist
  • PatternsError::PathTraversal if path is a system dir or has invalid encoding

§Example

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