Skip to content

Commit b0ad0a7

Browse files
composefs: Backwards compatibility for fetching image info
For older systems that do not have the `.imginfo` file, we revert back to our older logic of fetching the image info from registry Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent 235c272 commit b0ad0a7

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

crates/lib/src/bootc_composefs/state.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ pub(crate) async fn write_composefs_state(
211211
..
212212
} = &target_imgref;
213213

214-
println!("imgref: {target_imgref:#?}");
215-
216214
let imgref = get_imgref(&transport, &image_name);
217215

218216
let mut config = tini::Ini::new().section("origin").item(

crates/lib/src/bootc_composefs/status.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use fn_error_context::context;
66
use serde::{Deserialize, Serialize};
77

88
use crate::{
9-
bootc_composefs::boot::BootType,
9+
bootc_composefs::{boot::BootType, repo::get_imgref},
1010
composefs_consts::{COMPOSEFS_CMDLINE, ORIGIN_KEY_BOOT_DIGEST, TYPE1_ENT_PATH, USER_CFG},
1111
install::EFI_LOADER_INFO,
1212
parsers::{
@@ -21,7 +21,7 @@ use crate::{
2121
use std::str::FromStr;
2222

2323
use bootc_utils::try_deserialize_timestamp;
24-
use cap_std_ext::cap_std::fs::Dir;
24+
use cap_std_ext::{cap_std::fs::Dir, dirext::CapStdExtDirExt};
2525
use ostree_container::OstreeImageReference;
2626
use ostree_ext::container::{self as ostree_container};
2727
use ostree_ext::containers_image_proxy;
@@ -183,17 +183,29 @@ pub(crate) fn get_bootloader() -> Result<Bootloader> {
183183

184184
/// Reads the .imginfo file for the provided deployment
185185
#[context("Reading imginfo")]
186-
pub(crate) fn get_imginfo(storage: &Storage, deployment_id: &str) -> Result<ImgConfigManifest> {
186+
pub(crate) async fn get_imginfo(
187+
storage: &Storage,
188+
deployment_id: &str,
189+
imgref: &ImageReference,
190+
) -> Result<ImgConfigManifest> {
187191
let path = std::path::PathBuf::from(STATE_DIR_RELATIVE)
188192
.join(deployment_id)
189193
.join(format!("{deployment_id}.imginfo"));
190194

191-
let img_conf = storage
195+
let mut img_conf = storage
192196
.physical_root
193-
.read_to_string(&path)
197+
.open_optional(&path)
194198
.context("Failed to open file")?;
195199

196-
let img_conf = serde_json::from_str::<ImgConfigManifest>(&img_conf)
200+
let Some(img_conf) = &mut img_conf else {
201+
return get_container_manifest_and_config(&get_imgref(&imgref.transport, &imgref.image))
202+
.await;
203+
};
204+
205+
let mut buffer = String::new();
206+
img_conf.read_to_string(&mut buffer)?;
207+
208+
let img_conf = serde_json::from_str::<ImgConfigManifest>(&buffer)
197209
.context("Failed to parse file as JSON")?;
198210

199211
Ok(img_conf)
@@ -210,7 +222,7 @@ async fn boot_entry_from_composefs_deployment(
210222
let ostree_img_ref = OstreeImageReference::from_str(&img_name_from_config)?;
211223
let img_ref = ImageReference::from(ostree_img_ref);
212224

213-
let img_conf = get_imginfo(storage, &verity)?;
225+
let img_conf = get_imginfo(storage, &verity, &img_ref).await?;
214226

215227
let image_digest = img_conf.manifest.config().digest().to_string();
216228
let architecture = img_conf.config.architecture().to_string();

crates/lib/src/bootc_composefs/update.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ pub(crate) async fn upgrade_composefs(
367367
}
368368

369369
if opts.check {
370-
let current_manifest = get_imginfo(storage, &*composefs.cmdline.digest)?;
370+
let current_manifest =
371+
get_imginfo(storage, &*composefs.cmdline.digest, booted_imgref).await?;
371372
let diff = ManifestDiff::new(&current_manifest.manifest, &img_config.manifest);
372373
diff.print();
373374
return Ok(());

0 commit comments

Comments
 (0)