Common/FileSystem/Copy.rs
1//! # Copy Effect
2//!
3//! Defines the `ActionEffect` for copying a file or directory.
4
5use std::{path::PathBuf, sync::Arc};
6
7use super::FileSystemWriter::FileSystemWriter;
8use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
9
10/// Creates an effect that, when executed, will copy a file or directory from a
11/// source path to a target path.
12///
13/// It uses the `FileSystemWriter` capability from the environment to perform
14/// the actual file I/O.
15///
16/// # Parameters
17/// * `Source`: The `PathBuf` of the file or directory to copy.
18/// * `Target`: The `PathBuf` of the destination.
19/// * `Overwrite`: If `true`, an existing file or directory at the target path
20/// will be overwritten.
21///
22/// # Returns
23/// An `ActionEffect` that resolves to `()` on success.
24pub fn Copy(
25 Source:PathBuf,
26
27 Target:PathBuf,
28
29 Overwrite:bool,
30) -> ActionEffect<Arc<dyn FileSystemWriter>, CommonError, ()> {
31 ActionEffect::New(Arc::new(move |Writer:Arc<dyn FileSystemWriter>| {
32 let SourceClone = Source.clone();
33
34 let TargetClone = Target.clone();
35
36 Box::pin(async move { Writer.Copy(&SourceClone, &TargetClone, Overwrite).await })
37 }))
38}