Common/FileSystem/
Delete.rs

1//! # Delete Effect
2//!
3//! Defines the `ActionEffect` for deleting 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 delete a file or directory at
11/// the specified path.
12///
13/// It uses the `FileSystemWriter` capability from the environment to perform
14/// the actual file I/O.
15///
16/// # Parameters
17/// * `Path`: The `PathBuf` of the file or directory to delete.
18/// * `Recursive`: If `true`, deletes a directory and all its contents
19///   recursively. This has no effect if the path is a file.
20/// * `UseTrash`: If `true`, moves the item to the system's trash or recycling
21///   bin instead of permanently deleting it.
22///
23/// # Returns
24/// An `ActionEffect` that resolves to `()` on success.
25pub fn Delete(Path:PathBuf, Recursive:bool, UseTrash:bool) -> ActionEffect<Arc<dyn FileSystemWriter>, CommonError, ()> {
26	ActionEffect::New(Arc::new(move |Writer:Arc<dyn FileSystemWriter>| {
27		let PathClone = Path.clone();
28
29		Box::pin(async move { Writer.Delete(&PathClone, Recursive, UseTrash).await })
30	}))
31}