1use crate::error::IoResultExt;
2use crate::TempDir;
3use std::io;
4use std::path::PathBuf;
5
6pub fn create(path: PathBuf, permissions: Option<&std::fs::Permissions>) -> io::Result<TempDir> {
7 let mut dir_options: DirBuilder = std::fs::DirBuilder::new();
8 #[cfg(not(target_os = "wasi"))]
9 {
10 use std::os::unix::fs::{DirBuilderExt, PermissionsExt};
11 if let Some(p: &Permissions) = permissions {
12 dir_options.mode(p.mode());
13 }
14 }
15 dir_options
16 .create(&path)
17 .with_err_path(|| &path)
18 .map(|_| TempDir {
19 path: path.into_boxed_path(),
20 })
21}
22