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