Skip to main content

verify_file_safety

Function verify_file_safety 

Source
pub fn verify_file_safety(path: &Path) -> Result<()>
Expand description

Verifies the safety of a file for processing.

Performs comprehensive safety checks on a file to ensure it meets security requirements before processing. These checks include symlink detection and file size validation.

§Arguments

  • path - Reference to the path of the file to verify

§Returns

  • Ok(()) - If the file passes all safety checks
  • Err - If any safety check fails

§Safety Checks

  • Symlinks: Not allowed (returns error)
  • File size: Must be under 10MB
  • File type: Must be a regular file

§Examples

Verifies the safety of a file.

use std::fs;
use std::path::Path;
use ssg::verify_file_safety;
use tempfile::tempdir;

// Create temporary directory
let temp_dir = tempdir()?;
let file_path = temp_dir.path().join("index.md");

// Create test file
fs::write(&file_path, "Hello, world!")?;

// Perform verification
verify_file_safety(&file_path)?;

// Directory and file are automatically cleaned up

§Errors

Returns an error if:

  • File is a symlink
  • File size exceeds 10MB
  • Cannot read file metadata