Skip to main content

validate_path

Function validate_path 

Source
pub fn validate_path(
    path_str: &str,
    ctx: &PathContext,
) -> Result<PathBuf, String>
Expand description

Validates a path with canonicalization and prefix checking.

For existing paths, resolves symlinks via canonicalize() to prevent symlink-based escapes. For non-existent paths (writes), canonicalizes the parent directory and appends the filename.

§Arguments

  • path_str - Path string to validate
  • ctx - Validation context with allowed prefixes and requirements

§Returns

  • Ok(PathBuf) - Resolved path (canonical if possible)
  • Err(String) - Validation error message