From: Ian Jackson Date: Mon, 3 May 2021 11:59:12 +0000 (+0100) Subject: bundles: Provide Id::open X-Git-Tag: otter-0.6.0~452 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=36eb3d900dfe7dfc1395b085185cf5bcd2ed0164;p=otter.git bundles: Provide Id::open Signed-off-by: Ian Jackson --- diff --git a/src/bundles.rs b/src/bundles.rs index 10c5e9be..66e80c0b 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -101,6 +101,18 @@ impl Id { fn path(&self, instance: &InstanceName) -> String { b_file(instance, self.index, self.kind) } + + #[throws(IE)] + pub fn open(&self, instance_name: &InstanceName) -> Option { + let path = self.path(instance_name); + match File::open(&path) { + Ok(f) => Some(f), + Err(e) if e.kind() == ErrorKind::NotFound => None, + Err(e) => void::unreachable( + Err::(e).context(path).context("open bundle")? + ), + } + } } #[derive(Error,Debug)]