| 1 |
use crate::error::IoResultExt; |
| 2 |
use crate::TempDir; |
| 3 |
use std::path::PathBuf; |
| 4 |
use std::{fs, io}; |
| 5 |
|
| 6 |
fn not_supported<T>(msg: &str) -> io::Result<T> { |
| 7 |
Err(io::Error::new(io::ErrorKind::Other, msg)) |
| 8 |
} |
| 9 |
|
| 10 |
pub fn create(path: PathBuf, permissions: Option<&std::fs::Permissions>) -> io::Result<TempDir> { |
| 11 |
if permissions.map_or(false, |p| p.readonly()) { |
| 12 |
return not_supported("changing permissions is not supported on this platform"); |
| 13 |
} |
| 14 |
fs::create_dir(&path) |
| 15 |
.with_err_path(|| &path) |
| 16 |
.map(|_| TempDir { |
| 17 |
path: path.into_boxed_path(), |
| 18 |
}) |
| 19 |
} |