From 33a5dbbd51fc8d9ae180e8eac3f0600d8cbe37df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Mon, 3 Jun 2019 10:46:28 +0200 Subject: [PATCH] feat(index): implement delete() --- src/index.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/index.rs b/src/index.rs index 277bcc9..37397b5 100644 --- a/src/index.rs +++ b/src/index.rs @@ -130,8 +130,18 @@ pub fn find(cache: &Path, key: &str) -> Result, Error> { })) } -pub fn delete(_cache: &Path, _key: &str) { - unimplemented!(); +pub fn delete(cache: &Path, key: &str) -> Result<(), Error> { + let inserter = Inserter { + cache: cache.to_path_buf(), + key: String::from(key), + size: None, + sri: None, + time: None, + metadata: None, + uid: None, + gid: None, + }; + inserter.commit() } pub fn ls(_cache: &Path) { @@ -242,4 +252,15 @@ mod tests { let dir = tmp.path().to_owned(); assert_eq!(find(&dir, "hello").unwrap(), None); } + + #[test] + fn delete_basic() { + let tmp = tempfile::tempdir().unwrap(); + let dir = tmp.path().to_owned(); + let sri: Integrity = "sha1-deadbeef".parse().unwrap(); + let time = 1_234_567; + insert(&dir, "hello", sri).time(time).commit().unwrap(); + delete(&dir, "hello").unwrap(); + assert_eq!(find(&dir, "hello").unwrap(), None); + } }