1 | use crate::error::IoResultExt; |
2 | use crate::TempDir; |
3 | use std::io; |
4 | use std::path::PathBuf; |
5 | |
6 | pub 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 | |