From 36eb3d900dfe7dfc1395b085185cf5bcd2ed0164 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 3 May 2021 12:59:12 +0100 Subject: [PATCH] bundles: Provide Id::open Signed-off-by: Ian Jackson --- src/bundles.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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)] -- 2.30.2