diff options
Diffstat (limited to 'src/operations/mkdir.rs')
-rw-r--r-- | src/operations/mkdir.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/operations/mkdir.rs b/src/operations/mkdir.rs new file mode 100644 index 0000000..011b8cf --- /dev/null +++ b/src/operations/mkdir.rs @@ -0,0 +1,20 @@ +use crate::EntryWriteError; +use std::path::Path; + +pub fn make_directory<P>(path: P) -> Result<(), EntryWriteError> +where + P: AsRef<Path>, +{ + std::fs::DirBuilder::new().recursive(true).create(path)?; + Ok(()) +} + +pub fn make_parent_directory<P>(path: P) -> Result<(), EntryWriteError> +where + P: AsRef<Path>, +{ + match path.as_ref().parent() { + Some(parent) => make_directory(parent), + None => Ok(()), + } +} |