Add local CAS cleanup policy
This commit is contained in:
parent
00471bcec0
commit
21920b51b5
10 changed files with 184 additions and 8 deletions
|
|
@ -67,6 +67,15 @@ impl LocalCas {
|
|||
Ok(self.blob_path(hash)?.exists())
|
||||
}
|
||||
|
||||
pub fn remove(&self, hash: &BlobHash) -> Result<bool, CasError> {
|
||||
let path = self.blob_path(hash)?;
|
||||
if !path.exists() {
|
||||
return Ok(false);
|
||||
}
|
||||
std::fs::remove_file(path)?;
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub fn list(&self) -> Result<Vec<BlobInfo>, CasError> {
|
||||
let blobs = self.root.join("blobs");
|
||||
if !blobs.exists() {
|
||||
|
|
@ -154,4 +163,15 @@ mod tests {
|
|||
cas.get_to_path(&info.hash, &out).expect("get");
|
||||
assert_eq!(std::fs::read(out).expect("read"), b"hello geth");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cas_remove_deletes_blob_file() {
|
||||
let dir = tempfile::tempdir().expect("tempdir");
|
||||
let cas = LocalCas::new(dir.path());
|
||||
let info = cas.add_bytes(b"remove me").expect("add");
|
||||
|
||||
assert!(cas.remove(&info.hash).expect("remove"));
|
||||
assert!(!cas.has(&info.hash).expect("has after remove"));
|
||||
assert!(!cas.remove(&info.hash).expect("remove missing"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue