1use std::{
2 fs::create_dir_all,
3 io::{Error, Result},
4 path::{Path, PathBuf},
5};
6
7pub use find_dir::{find_directory, find_directory_or_create, this_directory};
8
9mod find_dir;
10mod find_file;
11
12pub fn ensure_directory(path: &Path) -> Result<PathBuf> {
26 if path.is_dir() {
27 path.canonicalize()
28 }
29 else {
30 match path.parent() {
31 Some(s) => s.canonicalize(),
32 None => Err(Error::from_raw_os_error(10006)),
33 }
34 }
35}
36
37pub fn ensure_file(path: &Path, name: &str) -> Result<PathBuf> {
52 if path.is_file() { path.canonicalize() } else { Ok(path.canonicalize()?.join(name)) }
53}