Mountain/IPC/WindServiceHandlers/FileSystem/Managed/
FileDelete.rs1use std::{path::PathBuf, sync::Arc};
4
5use CommonLibrary::{
6 Environment::Requires::Requires,
7 Error::CommonError::CommonError,
8 FileSystem::FileSystemWriter::FileSystemWriter,
9};
10use serde_json::Value;
11
12use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
13
14pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
15 let path = Arguments
16 .get(0)
17 .ok_or("Missing file path".to_string())?
18 .as_str()
19 .ok_or("File path must be a string".to_string())?;
20
21 let provider:Arc<dyn FileSystemWriter> = RunTime.Environment.Require();
22
23 provider
24 .Delete(&PathBuf::from(path), false, false)
25 .await
26 .map_err(|e:CommonError| format!("Failed to delete file: {}", e))?;
27
28 dev_log!("vfs-verbose", "deleted: {}", path);
29
30 Ok(Value::Null)
31}