Mountain/RPC/CocoonService/FileSystem/
DeleteFile.rs1#![allow(non_snake_case)]
2
3use tonic::{Response, Status};
6
7use crate::{
8 RPC::CocoonService::CocoonServiceImpl,
9 Vine::Generated::{DeleteFileRequest, Empty},
10 dev_log,
11};
12
13pub async fn Fn(_Service:&CocoonServiceImpl, Request:DeleteFileRequest) -> Result<Response<Empty>, Status> {
14 let Path = CocoonServiceImpl::UriToPath(Request.uri.as_ref())
15 .ok_or_else(|| Status::invalid_argument("delete_file: missing URI"))?;
16
17 dev_log!("cocoon", "[CocoonService] delete_file: {:?}", Path);
18
19 if Path.is_dir() {
20 tokio::fs::remove_dir_all(&Path).await
21 } else {
22 tokio::fs::remove_file(&Path).await
23 }
24 .map_err(|Error| Status::internal(format!("delete_file: {}: {}", Path.display(), Error)))?;
25
26 Ok(Response::new(Empty {}))
27}