pub async fn copy_files_parallel(
sources_and_destinations: &[(PathBuf, PathBuf)],
) -> Result<()>Expand description
Copies multiple files concurrently using parallel processing.
This function performs multiple file copy operations in parallel, which can significantly improve performance when copying many files, especially on systems with fast storage and multiple CPU cores.
§Arguments
sources_and_destinations- A slice of (source, destination) path pairs
§Returns
Ok(())if all files were copied successfullyErrif any copy operation fails, with details about all failures
§Examples
use agpm_cli::utils::fs::parallel::copy_files_parallel;
use std::path::PathBuf;
let copy_operations = vec![
(PathBuf::from("src/agent1.md"), PathBuf::from("output/agent1.md")),
(PathBuf::from("src/agent2.md"), PathBuf::from("output/agent2.md")),
(PathBuf::from("src/snippet.md"), PathBuf::from("output/snippet.md")),
];
copy_files_parallel(©_operations).await?;
println!("All files copied successfully!");§Features
- Parallel execution: Uses thread pool for concurrent operations
- Automatic directory creation: Creates destination directories as needed
- Atomic behavior: Either all files copy successfully or none do
- Progress tracking: Can be combined with progress bars for user feedback
§Performance Characteristics
- Best for many small to medium files
- Scales with available CPU cores and I/O bandwidth
- May not improve performance for very large files (I/O bound)
- Respects filesystem limits on concurrent operations
§Error Handling
All copy operations must succeed for the function to return Ok(()). If any
operation fails, detailed error information is provided for troubleshooting.
§See Also
copy_dirs_parallelfor directory copyingsuper::atomic::atomic_write_multiplefor writing multiple files