Common/FileSystem/
StatFile.rs

1//! # StatFile Effect
2//!
3//! Defines the `ActionEffect` for retrieving metadata about a file or
4//! directory.
5
6use std::{path::PathBuf, sync::Arc};
7
8use super::{DTO::FileSystemStatDTO::FileSystemStatDTO, FileSystemReader::FileSystemReader};
9use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
10
11/// Creates an effect that, when executed, will retrieve metadata (such as file
12/// type, size, and modification times) for a given path.
13///
14/// It uses the `FileSystemReader` capability from the environment to perform
15/// the underlying `stat` system call asynchronously.
16///
17/// # Parameters
18/// * `Path`: The `PathBuf` of the file or directory to stat.
19///
20/// # Returns
21/// An `ActionEffect` that resolves with a `FileSystemStatDTO`.
22pub fn StatFile(Path:PathBuf) -> ActionEffect<Arc<dyn FileSystemReader>, CommonError, FileSystemStatDTO> {
23	ActionEffect::New(Arc::new(move |Reader:Arc<dyn FileSystemReader>| {
24		let PathClone = Path.clone();
25
26		Box::pin(async move { Reader.StatFile(&PathClone).await })
27	}))
28}