copy_dirs_parallel

Function copy_dirs_parallel 

Source
pub async fn copy_dirs_parallel(
    sources_and_destinations: &[(PathBuf, PathBuf)],
) -> Result<()>
Expand description

Copies multiple directories concurrently.

This function performs multiple directory copy operations in parallel, which can improve performance when copying several separate directory trees. Each directory is copied recursively using the same logic as super::dirs::copy_dir.

§Arguments

  • sources_and_destinations - A slice of (source, destination) directory pairs

§Returns

  • Ok(()) if all directories were copied successfully
  • Err if any copy operation fails, with details about all failures

§Examples

use agpm_cli::utils::fs::parallel::copy_dirs_parallel;
use std::path::PathBuf;

let copy_operations = vec![
    (PathBuf::from("cache/agents"), PathBuf::from("output/agents")),
    (PathBuf::from("cache/snippets"), PathBuf::from("output/snippets")),
    (PathBuf::from("cache/templates"), PathBuf::from("output/templates")),
];

copy_dirs_parallel(&copy_operations).await?;
println!("All directories copied successfully!");

§Features

  • Recursive copying: Each directory is copied with all subdirectories
  • Parallel execution: Multiple directory trees copied concurrently
  • Atomic behavior: Either all directories copy successfully or operation fails
  • Automatic creation: Destination directories are created as needed

§Use Cases

  • Copying multiple resource categories simultaneously
  • Batch operations on directory structures
  • Backup operations for multiple directories
  • Installation processes involving multiple components

§Performance Considerations

  • Best performance with multiple separate directory trees
  • May not improve performance if directories share the same disk
  • Memory usage scales with number of directories and their sizes
  • Respects filesystem concurrent operation limits

§See Also