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/rm.rs | |
download | vagabond-1.0.zip |
Initial commitv1.0
Diffstat (limited to 'src/operations/rm.rs')
-rw-r--r-- | src/operations/rm.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/operations/rm.rs b/src/operations/rm.rs new file mode 100644 index 0000000..846a094 --- /dev/null +++ b/src/operations/rm.rs @@ -0,0 +1,23 @@ +use crate::EntryWriteError; +use crate::{get_entry, EntryType}; +use std::path::Path; + +pub fn remove<P>(path: P) -> Result<(), EntryWriteError> +where + P: AsRef<Path>, +{ + let entry = get_entry(&path)?; + match entry.entry_type { + EntryType::File => std::fs::remove_file(&path)?, + EntryType::Directory => std::fs::remove_dir_all(&path)?, + } + Ok(()) +} + +pub fn remove_file<P>(path: P) -> Result<(), EntryWriteError> +where + P: AsRef<Path>, +{ + std::fs::remove_file(path)?; + Ok(()) +} |