Skip to content

Commit

Permalink
containers: Only open image once
Browse files Browse the repository at this point in the history
I was doing some further reading of code and noticed we opened
the image multiple times.  I think that's not a big deal, we probably
will reuse connections to the registry etc. internally.  But fix
it anyways.
  • Loading branch information
cgwalters committed Dec 14, 2021
1 parent 27887c7 commit 0570c50
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/src/container/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ impl LayeredImageImporter {
&self.repo,
&mut proxy,
target_imgref,
&self.proxy_img,
&import.manifest,
None,
true,
Expand Down
18 changes: 12 additions & 6 deletions lib/src/container/unencapsulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,13 @@ pub async fn unencapsulate(
options: Option<UnencapsulateOptions>,
) -> Result<Import> {
let mut proxy = ImageProxy::new().await?;
let (manifest, image_digest) = fetch_manifest_impl(&mut proxy, imgref).await?;
let oi = &proxy.open_image(&imgref.imgref.to_string()).await?;
let (image_digest, raw_manifest) = proxy.fetch_manifest(oi).await?;
let manifest = serde_json::from_slice(&raw_manifest)?;
let ostree_commit =
unencapsulate_from_manifest_impl(repo, &mut proxy, imgref, &manifest, options, false)
unencapsulate_from_manifest_impl(repo, &mut proxy, imgref, oi, &manifest, options, false)
.await?;
proxy.close_image(oi).await?;
Ok(Import {
ostree_commit,
image_digest,
Expand Down Expand Up @@ -227,6 +230,7 @@ pub(crate) async fn unencapsulate_from_manifest_impl(
repo: &ostree::Repo,
proxy: &mut ImageProxy,
imgref: &OstreeImageReference,
oi: &containers_image_proxy::OpenedImage,
manifest: &oci_spec::image::ImageManifest,
options: Option<UnencapsulateOptions>,
ignore_layered: bool,
Expand All @@ -251,8 +255,7 @@ pub(crate) async fn unencapsulate_from_manifest_impl(
layer.digest().as_str(),
layer.size()
);
let oi = proxy.open_image(&imgref.imgref.to_string()).await?;
let (blob, driver) = fetch_layer_decompress(proxy, &oi, layer).await?;
let (blob, driver) = fetch_layer_decompress(proxy, oi, layer).await?;
let blob = ProgressReader {
reader: blob,
progress: options.progress,
Expand Down Expand Up @@ -281,8 +284,11 @@ pub async fn unencapsulate_from_manifest(
options: Option<UnencapsulateOptions>,
) -> Result<String> {
let mut proxy = ImageProxy::new().await?;
let r = unencapsulate_from_manifest_impl(repo, &mut proxy, imgref, manifest, options, false)
.await?;
let oi = &proxy.open_image(&imgref.imgref.to_string()).await?;
let r =
unencapsulate_from_manifest_impl(repo, &mut proxy, imgref, oi, manifest, options, false)
.await?;
proxy.close_image(oi).await?;
// FIXME write ostree commit after proxy finalization
proxy.finalize().await?;
Ok(r)
Expand Down

0 comments on commit 0570c50

Please sign in to comment.