pub fn verify_and_copy_files(src: &Path, dst: &Path) -> Result<()>Expand description
Validates and copies files from source to destination.
This function performs comprehensive safety checks before copying files, including path validation, symlink detection, and size limitations.
§Arguments
src- Source path to copy fromdst- Destination path to copy to
§Returns
Returns Ok(()) if the copy operation succeeds, or an error if:
- Source path is invalid or inaccessible
- Source contains symlinks (not allowed)
- Files exceed size limits (default: 10MB)
- Destination cannot be created or written to
§Example
use std::path::Path;
use ssg::verify_and_copy_files;
fn main() -> anyhow::Result<()> {
let source = Path::new("source_directory");
let destination = Path::new("destination_directory");
verify_and_copy_files(source, destination)?;
println!("Files copied successfully");
Ok(())
}§Security
This function implements several security measures:
- Path traversal prevention
- Symlink restriction
- File size limits
- Permission validation