From b4772d1c43147341a36a4e7e45c9f4093208d9c5 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Thu, 31 Dec 2020 10:03:17 +0100 Subject: [PATCH] tape: new inventory helper - lookup_media_set_pool --- src/tape/inventory.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs index 383c8b8f..3f97f777 100644 --- a/src/tape/inventory.rs +++ b/src/tape/inventory.rs @@ -346,6 +346,37 @@ impl Inventory { self.media_set_start_times.get(media_set_uuid).map(|t| *t) } + /// Lookup media set pool + pub fn lookup_media_set_pool(&self, media_set_uuid: &Uuid) -> Result { + + let mut last_pool = None; + + for media in self.map.values() { + match media.media_set_label { + None => continue, + Some(MediaSetLabel { ref uuid, .. }) => { + if uuid != media_set_uuid { + continue; + } + if let Some((pool, _)) = self.lookup_media_pool(&media.label.uuid) { + if let Some(last_pool) = last_pool { + if last_pool != pool { + bail!("detected media set with inconsistent pool assignment - internal error"); + } + } else { + last_pool = Some(pool); + } + } + } + } + } + + match last_pool { + Some(pool) => Ok(pool.to_string()), + None => bail!("media set {} is incomplete - unable to lookup pool"), + } + } + /// Compute a single media sets pub fn compute_media_set_members(&self, media_set_uuid: &Uuid) -> Result {