Common/FileSystem/
FileSystemWriter.rs

1//! # FileSystemWriter Trait
2//!
3//! Defines the abstract service trait for write and modification filesystem
4//! capabilities.
5
6use std::path::PathBuf;
7
8use async_trait::async_trait;
9
10use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
11
12/// An abstract service contract for an environment component that can perform
13/// write and modification filesystem operations.
14///
15/// This trait is implemented by `MountainEnvironment` and typically uses
16/// `tokio::fs` to fulfill the contract. Separating write operations from read
17/// operations enhances security by allowing capabilities to be granted on a
18/// need-to-know basis.
19#[async_trait]
20pub trait FileSystemWriter: Environment + Send + Sync {
21	/// Writes byte content to a file.
22	///
23	/// # Parameters
24	/// * `Path`: The path of the file to write to.
25	/// * `Content`: The byte vector to write.
26	/// * `Create`: If `true`, the file will be created if it does not exist.
27	/// * `Overwrite`: If `true`, an existing file will be overwritten.
28	async fn WriteFile(&self, Path:&PathBuf, Content:Vec<u8>, Create:bool, Overwrite:bool) -> Result<(), CommonError>;
29
30	/// Creates a directory at the specified path.
31	///
32	/// # Parameters
33	/// * `Path`: The path of the directory to create.
34	/// * `Recursive`: If `true`, creates all parent directories as needed.
35	async fn CreateDirectory(&self, Path:&PathBuf, Recursive:bool) -> Result<(), CommonError>;
36
37	/// Deletes a file or directory.
38	///
39	/// # Parameters
40	/// * `Path`: The path of the item to delete.
41	/// * `Recursive`: If `true`, deletes a directory and all its contents.
42	/// * `UseTrash`: If `true`, moves the item to the system's trash or
43	///   recycling bin instead of permanently deleting it.
44	async fn Delete(&self, Path:&PathBuf, Recursive:bool, UseTrash:bool) -> Result<(), CommonError>;
45
46	/// Renames (moves) a file or directory.
47	///
48	/// # Parameters
49	/// * `Source`: The original path of the item.
50	/// * `Target`: The new path for the item.
51	/// * `Overwrite`: If `true`, an existing item at the target path will be
52	///   overwritten.
53	async fn Rename(&self, Source:&PathBuf, Target:&PathBuf, Overwrite:bool) -> Result<(), CommonError>;
54
55	/// Copies a file or directory.
56	///
57	/// # Parameters
58	/// * `Source`: The path of the item to copy.
59	/// * `Target`: The destination path for the copy.
60	/// * `Overwrite`: If `true`, an existing item at the target path will be
61	///   overwritten.
62	async fn Copy(&self, Source:&PathBuf, Target:&PathBuf, Overwrite:bool) -> Result<(), CommonError>;
63
64	/// Creates a new, empty file at the specified path. This is a convenience
65	/// method that will fail if the file already exists.
66	async fn CreateFile(&self, Path:&PathBuf) -> Result<(), CommonError>;
67}