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