diff --git a/src/index.rs b/src/index.rs index e011286..8852107 100644 --- a/src/index.rs +++ b/src/index.rs @@ -379,6 +379,57 @@ async fn bucket_entries_async(bucket: &Path) -> std::io::Result Self { + Default::default() + } + + /// Set the remove fully option + /// If remove_fully is set to true then the index file itself will be physically deleted rather than appending a null. + pub fn remove_fully(mut self, remove_fully: bool) -> Self { + self.remove_fully = remove_fully; + self + } + + /// Removes an individual index metadata entry. The associated content will be left in the cache. + pub fn remove_sync(self, cache: P, key: K) -> Result<()> + where + P: AsRef, + K: AsRef, + { + if !self.remove_fully { + delete(cache.as_ref(), key.as_ref()) + } else { + let bucket = bucket_path(cache.as_ref(), key.as_ref()); + fs::remove_file(&bucket) + .with_context(|| format!("Failed to remove bucket at {bucket:?}")) + } + } + + /// Removes an individual index metadata entry. The associated content will be left in the cache. + pub async fn remove(self, cache: P, key: K) -> Result<()> + where + P: AsRef, + K: AsRef, + { + if !self.remove_fully { + delete_async(cache.as_ref(), key.as_ref()).await + } else { + let bucket = bucket_path(cache.as_ref(), key.as_ref()); + crate::async_lib::remove_file(&bucket) + .await + .with_context(|| format!("Failed to remove bucket at {bucket:?}")) + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/lib.rs b/src/lib.rs index 0b533ea..07f0826 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,7 +174,7 @@ mod put; mod rm; pub use errors::{Error, Result}; -pub use index::Metadata; +pub use index::{Metadata, RemoveOpts}; pub use get::*; #[cfg(feature = "link_to")]