Skip to main content

verify_and_copy_files

Function verify_and_copy_files 

Source
pub fn verify_and_copy_files(src: &Path, dst: &Path) -> Result<(), SsgError>
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 from
  • dst - 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

§Examples

use ssg::verify_and_copy_files;
use tempfile::tempdir;
use std::fs;

let src_dir = tempdir().unwrap();
let dst_dir = tempdir().unwrap();
fs::write(src_dir.path().join("a.txt"), "data").unwrap();
verify_and_copy_files(src_dir.path(), dst_dir.path()).unwrap();
assert!(dst_dir.path().join("a.txt").exists());

§Security

This function implements several security measures:

  • Path traversal prevention
  • Symlink restriction
  • File size limits
  • Permission validation