feat(index): implement delete()

This commit is contained in:
Kat Marchán 2019-06-03 10:46:28 +02:00
parent 44eb2acc98
commit 33a5dbbd51
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
1 changed files with 23 additions and 2 deletions

View File

@ -130,8 +130,18 @@ pub fn find(cache: &Path, key: &str) -> Result<Option<Entry>, 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);
}
}