Add local CAS cleanup policy
This commit is contained in:
parent
00471bcec0
commit
21920b51b5
10 changed files with 184 additions and 8 deletions
|
|
@ -235,6 +235,14 @@ impl Store {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn delete_cas_object(&self, hash: &str) -> Result<(), StoreError> {
|
||||
self.conn
|
||||
.execute("DELETE FROM cas_objects WHERE hash = ?1", params![hash])?;
|
||||
self.conn
|
||||
.execute("DELETE FROM cas_pins WHERE hash = ?1", params![hash])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn list_cas_objects(&self) -> Result<Vec<CasObject>, StoreError> {
|
||||
let mut stmt = self.conn.prepare(
|
||||
"SELECT hash, size_bytes, path FROM cas_objects ORDER BY created_at_ms, hash",
|
||||
|
|
@ -765,4 +773,19 @@ mod tests {
|
|||
assert!(!store.is_cas_object_pinned(hash).expect("unpinned again"));
|
||||
assert!(store.list_cas_pins().expect("pins").is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deleting_cas_object_removes_pin_metadata() {
|
||||
let store = Store::open_memory().expect("open");
|
||||
let hash = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
|
||||
store
|
||||
.record_cas_object(hash, 10, "/tmp/blob")
|
||||
.expect("record object");
|
||||
store.pin_cas_object(hash).expect("pin");
|
||||
|
||||
store.delete_cas_object(hash).expect("delete object");
|
||||
|
||||
assert!(store.list_cas_objects().expect("objects").is_empty());
|
||||
assert!(store.list_cas_pins().expect("pins").is_empty());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue