vagabond/src/operations/rm.rs

24 lines
512 B
Rust

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(())
}