From 96d1eb907dfeba9d10735ebbd7d9c1cba36236f0 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 13 Dec 2021 20:34:51 -0500 Subject: [PATCH] containers: Only open image once 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. --- lib/src/container/store.rs | 1 + lib/src/container/unencapsulate.rs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/src/container/store.rs b/lib/src/container/store.rs index 2f159ba8..10caa980 100644 --- a/lib/src/container/store.rs +++ b/lib/src/container/store.rs @@ -275,6 +275,7 @@ impl LayeredImageImporter { &self.repo, &mut proxy, target_imgref, + &self.proxy_img, &import.manifest, None, true, diff --git a/lib/src/container/unencapsulate.rs b/lib/src/container/unencapsulate.rs index ebf8426a..e4c315ef 100644 --- a/lib/src/container/unencapsulate.rs +++ b/lib/src/container/unencapsulate.rs @@ -181,10 +181,13 @@ pub async fn unencapsulate( options: Option, ) -> Result { 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, @@ -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, ignore_layered: bool, @@ -251,7 +255,6 @@ 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 = ProgressReader { reader: blob, @@ -281,8 +284,11 @@ pub async fn unencapsulate_from_manifest( options: Option, ) -> Result { 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)