blob: 512a54e2b2b525adc26a87deb4762dddc2d2c7f3 [file] [log] [blame]
use crate::error::IoResultExt;
use crate::TempDir;
use std::path::PathBuf;
use std::{fs, io};
fn not_supported<T>(msg: &str) -> io::Result<T> {
Err(io::Error::new(io::ErrorKind::Other, msg))
}
pub fn create(
path: PathBuf,
permissions: Option<&std::fs::Permissions>,
keep: bool,
) -> io::Result<TempDir> {
if permissions.map_or(false, |p| p.readonly()) {
return not_supported("changing permissions is not supported on this platform");
}
fs::create_dir(&path)
.with_err_path(|| &path)
.map(|_| TempDir {
path: path.into_boxed_path(),
keep,
})
}