Skip to main content

copy_dir_all

Function copy_dir_all 

Source
pub fn copy_dir_all(src: &Path, dst: &Path) -> Result<(), SsgError>
Expand description

Recursively copies a directory whilst maintaining structure and attributes.

Performs a deep copy of a directory tree, preserving file attributes and handling nested directories. Uses parallel processing for improved performance.

§Arguments

  • src - Source directory path
  • dst - Destination directory path

§Returns

  • Ok(()) - If the copy operation succeeds
  • Err - If any part of the copy operation fails

§Performance

Uses rayon for parallel processing of files, significantly improving performance for directories with many files.

§Safety

  • Verifies file safety before copying
  • Maintains original file permissions
  • Handles circular references

§Examples

use ssg::fs_ops::copy_dir_all;
use tempfile::tempdir;
use std::fs;

let src = tempdir().unwrap();
let dst = tempdir().unwrap();
fs::write(src.path().join("z.txt"), "z").unwrap();
copy_dir_all(src.path(), dst.path()).unwrap();
assert!(dst.path().join("z.txt").exists());