From 8f410d1ead74b979481f1488a4dcddd33ea829c7 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Thu, 25 Aug 2022 21:27:39 +1200 Subject: Initial commit --- src/operations/rm.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/operations/rm.rs (limited to 'src/operations/rm.rs') 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

(path: P) -> Result<(), EntryWriteError> +where + P: AsRef, +{ + 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

(path: P) -> Result<(), EntryWriteError> +where + P: AsRef, +{ + std::fs::remove_file(path)?; + Ok(()) +} -- cgit v1.2.3-70-g09d2