diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2022-08-25 21:27:39 +1200 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2022-08-25 21:27:39 +1200 |
commit | 8f410d1ead74b979481f1488a4dcddd33ea829c7 (patch) | |
tree | 2f22fd930c8d0cdb4de53fef473f7770073e14d5 /src/operations/mkdir.rs | |
download | vagabond-8f410d1ead74b979481f1488a4dcddd33ea829c7.zip |
Initial commitv1.0
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(()), + } +} |