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