Skip to main content

Mountain/RPC/CocoonService/FileSystem/
CreateDirectory.rs

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