summaryrefslogtreecommitdiff
path: root/src/operations/mkdir.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2022-08-25 21:27:39 +1200
committerBen Bridle <bridle.benjamin@gmail.com>2022-08-25 21:27:39 +1200
commit8f410d1ead74b979481f1488a4dcddd33ea829c7 (patch)
tree2f22fd930c8d0cdb4de53fef473f7770073e14d5 /src/operations/mkdir.rs
downloadvagabond-79748a9b6c03b6d1926a765c2f0944ec2575f4cd.zip
Initial commitv1.0
Diffstat (limited to 'src/operations/mkdir.rs')
-rw-r--r--src/operations/mkdir.rs20
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(()),
+ }
+}