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
44
45
46
47
48
49
50
51
52
53
use std::{
fs::create_dir_all,
io::{Error, Result},
path::{Path, PathBuf},
};
pub use find_dir::{find_directory, find_directory_or_create};
mod find_dir;
mod find_file;
pub fn ensure_directory(path: &Path) -> Result<PathBuf> {
if path.is_dir() {
path.canonicalize()
}
else {
match path.parent() {
Some(s) => s.canonicalize(),
None => Err(Error::from_raw_os_error(10006)),
}
}
}
pub fn ensure_file(path: &Path, name: &str) -> Result<PathBuf> {
if path.is_file() { path.canonicalize() } else { Ok(path.canonicalize()?.join(name)) }
}