Mountain/RPC/CocoonService/GenericRequest/FileSystem/
Delete.rs1use serde_json::Value;
2use tonic::Response;
3use ::Vine::Generated::GenericResponse;
4
5pub async fn Fn(RequestId:u64, Params:Value) -> Response<GenericResponse> {
6 let Path = Params
7 .as_str()
8 .or_else(|| Params.get("path").and_then(|V| V.as_str()))
9 .unwrap_or("");
10
11 let Result = if std::path::Path::new(Path).is_dir() {
12 tokio::fs::remove_dir_all(Path).await
13 } else {
14 tokio::fs::remove_file(Path).await
15 };
16
17 match Result {
18 Ok(()) => super::OkResponse(RequestId, &Value::Null),
19
20 Err(Error) => super::ErrResponse(RequestId, -32000, format!("fs.delete: {}", Error)),
21 }
22}