1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::{fs::create_dir_all, path::Path};
#[derive(Debug)]
pub struct MkdirPFailure;
pub fn mkdir_p(path: &Path) -> Result<(), MkdirPFailure> {
create_dir_all(path).map_err(|_e| MkdirPFailure)
}
#[cfg(test)]
mod tests {
use tempfile::TempDir;
use super::*;
#[test]
fn mkdir_p_works() {
let tmp_root = TempDir::new().unwrap();
let path = tmp_root.path().join("something");
assert!(!path.is_dir());
mkdir_p(&path).unwrap();
assert!(path.is_dir());
let path = tmp_root.path().join("something else");
assert!(!path.is_dir());
mkdir_p(&path).unwrap();
assert!(path.is_dir());
mkdir_p(&path).unwrap(); assert!(path.is_dir());
let path = tmp_root.path().join("something\0with NULL");
mkdir_p(&path).unwrap_err();
}
}