1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use crate::error::IoResultExt;
use crate::TempDir;
use std::io;
use std::path::PathBuf;

pub fn create(path: PathBuf, permissions: Option<&std::fs::Permissions>) -> io::Result<TempDir> {
    let mut dir_options = std::fs::DirBuilder::new();
    #[cfg(not(target_os = "wasi"))]
    {
        use std::os::unix::fs::{DirBuilderExt, PermissionsExt};
        if let Some(p) = permissions {
            dir_options.mode(p.mode());
        }
    }
    dir_options
        .create(&path)
        .with_err_path(|| &path)
        .map(|_| TempDir {
            path: path.into_boxed_path(),
        })
}