Skip to main content

Mountain/RPC/CocoonService/FileSystem/
CreateDirectory.rs

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