tempfile/dir/imp/
unix.rs

1use crate::error::IoResultExt;
2use crate::TempDir;
3use std::io;
4use std::path::PathBuf;
5
6pub fn create(
7    path: PathBuf,
8    permissions: Option<&std::fs::Permissions>,
9    keep: bool,
10) -> io::Result<TempDir> {
11    let mut dir_options = 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 {
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}