Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #403 from cgwalters/query-image-commit
Browse files Browse the repository at this point in the history
container: Add an API to query information from a commit object
  • Loading branch information
cgwalters authored Nov 10, 2022
2 parents c0359aa + ee502e5 commit b2e3e56
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/src/container/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,6 @@ impl ImageImporter {

// Destructure to transfer ownership to thread
let repo = self.repo;
let imgref = self.target_imgref.unwrap_or(self.imgref);
let state = crate::tokio_util::spawn_blocking_cancellable_flatten(
move |cancellable| -> Result<Box<LayeredImageState>> {
use cap_std_ext::rustix::fd::AsRawFd;
Expand Down Expand Up @@ -864,7 +863,7 @@ impl ImageImporter {

// Here we re-query state just to run through the same code path,
// though it'd be cheaper to synthesize it from the data we already have.
let state = query_image(repo, &imgref)?.unwrap();
let state = query_image_commit(repo, &merged_commit)?;
Ok(state)
},
)
Expand Down Expand Up @@ -893,11 +892,16 @@ pub fn query_image_ref(
) -> Result<Option<Box<LayeredImageState>>> {
let ostree_ref = &ref_for_image(imgref)?;
let merge_rev = repo.resolve_rev(ostree_ref, true)?;
let (merge_commit, merge_commit_obj) = if let Some(r) = merge_rev {
(r.to_string(), repo.load_commit(r.as_str())?.0)
} else {
return Ok(None);
};
merge_rev
.map(|r| query_image_commit(repo, r.as_str()))
.transpose()
}

/// Query metadata for a pulled image via an OSTree commit digest.
/// The digest must refer to a pulled container image's merge commit.
pub fn query_image_commit(repo: &ostree::Repo, commit: &str) -> Result<Box<LayeredImageState>> {
let merge_commit = commit.to_string();
let merge_commit_obj = repo.load_commit(commit)?.0;
let commit_meta = &merge_commit_obj.child_value(0);
let commit_meta = &ostree::glib::VariantDict::new(Some(commit_meta));
let (manifest, manifest_digest) = manifest_data_from_commitmeta(commit_meta)?;
Expand All @@ -920,7 +924,7 @@ pub fn query_image_ref(
configuration,
});
tracing::debug!(state = ?state);
Ok(Some(state))
Ok(state)
}

/// Query metadata for a pulled image.
Expand Down

0 comments on commit b2e3e56

Please sign in to comment.