Skip to main content

Mountain/RPC/CocoonService/FileSystem/
DeleteFile.rs

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