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