diff options
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(()) +} |