From c8545e15a0f05d93e1f76d641596b6597fe1daf0 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 3 Oct 2023 13:57:54 -0400 Subject: [PATCH] lib/container: Add APIs to retrieve version conveniently This also relates to https://github.com/containers/oci-spec-rs/pull/143 Basically getting the version from the config requires a helper, this is a lot more convenient. --- lib/src/container/store.rs | 14 ++++++++++++++ lib/tests/it/main.rs | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/src/container/store.rs b/lib/src/container/store.rs index 23960b5d..901067b0 100644 --- a/lib/src/container/store.rs +++ b/lib/src/container/store.rs @@ -140,6 +140,13 @@ impl LayeredImageState { self.base_commit.as_str() } } + + /// Retrieve the container image version. + pub fn version(&self) -> Option<&str> { + self.configuration + .as_ref() + .and_then(super::version_for_config) + } } /// Locally cached metadata for an update to an existing image. @@ -153,6 +160,13 @@ pub struct CachedImageUpdate { pub manifest_digest: String, } +impl CachedImageUpdate { + /// Retrieve the container image version. + pub fn version(&self) -> Option<&str> { + super::version_for_config(&self.config) + } +} + /// Context for importing a container image. #[derive(Debug)] pub struct ImageImporter { diff --git a/lib/tests/it/main.rs b/lib/tests/it/main.rs index 483e955c..5a10b816 100644 --- a/lib/tests/it/main.rs +++ b/lib/tests/it/main.rs @@ -780,13 +780,15 @@ r usr/bin/bash bash-v0 { let cached = store::query_image_ref(fixture.destrepo(), &imgref.imgref) .unwrap() - .unwrap() - .cached_update .unwrap(); + assert_eq!(cached.version(), Some("42.0")); + + let cached_update = cached.cached_update.unwrap(); assert_eq!( - cached.manifest_digest.as_str(), + cached_update.manifest_digest.as_str(), prep.manifest_digest.as_str() ); + assert_eq!(cached_update.version(), Some("42.0")); } let to_fetch = prep.layers_to_fetch().collect::>>()?; assert_eq!(to_fetch.len(), 2);