From e7b80cca1c93efda1576e19846ebf089ff6cfa95 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 3 May 2022 21:09:59 +0000 Subject: ripple/fossil: handle missing blobs more gracefully Change-Id: I8a928b57ecc81bea31d757e73b9ece9474628db4 --- ripple/fossil/src/lib.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'ripple/fossil/src/lib.rs') diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs index 004cf45..007a771 100644 --- a/ripple/fossil/src/lib.rs +++ b/ripple/fossil/src/lib.rs @@ -207,18 +207,14 @@ impl Store { Some(store::Chunk::decode(&*buf).unwrap()) } - pub fn read_blob(&self, ident: Digest) -> Vec { + pub fn read_blob(&self, ident: Digest) -> Option> { let mut buffer = Vec::new(); - self.open_blob(ident).read_to_end(&mut buffer).unwrap(); - buffer + self.open_blob(ident)?.read_to_end(&mut buffer).unwrap(); + Some(buffer) } - pub fn open_blob(&self, ident: Digest) -> Blob { - let buf = self - .blobs - .get(&*ident.as_bytes()) - .unwrap() - .expect("blob not found"); + pub fn open_blob(&self, ident: Digest) -> Option { + let buf = self.blobs.get(&*ident.as_bytes()).unwrap()?; let store::Blob { mut chunks, @@ -241,7 +237,7 @@ impl Store { }) .collect(); - Blob(bao::decode::Decoder::new_outboard( + Some(Blob(bao::decode::Decoder::new_outboard( RawBlob { store: self, chunks, @@ -250,7 +246,7 @@ impl Store { }, io::Cursor::new(bao_inline), &ident, - )) + ))) } } @@ -537,5 +533,5 @@ fn read_write() { // TODO(edef): use a temporary file let store = Store::open("fossil.db").unwrap(); let ident = store.write_blob(&data); - assert_eq!(data, store.read_blob(ident)); + assert_eq!(Some(data), store.read_blob(ident)); } -- cgit 1.4.1