Skip to content

Commit 34e563e

Browse files
composefs: Use ManifestDiff for getting manifest diff
Now that we store the current deployment's manifest locally, we can replace the ugly stuff with a simple call to `ManifestDiff::new` Signed-off-by: Pragyan Poudyal <[email protected]>
1 parent 81b09a0 commit 34e563e

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

crates/lib/src/bootc_composefs/status.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,24 @@ pub(crate) fn get_bootloader() -> Result<Bootloader> {
181181
}
182182
}
183183

184+
/// Reads the .imginfo file for the provided deployment
185+
#[context("Reading imginfo")]
186+
pub(crate) fn get_imginfo(storage: &Storage, deployment_id: &str) -> Result<ImgConfigManifest> {
187+
let path = std::path::PathBuf::from(STATE_DIR_RELATIVE)
188+
.join(deployment_id)
189+
.join(format!("{deployment_id}.imginfo"));
190+
191+
let img_conf = storage
192+
.physical_root
193+
.read_to_string(&path)
194+
.context("Failed to open file")?;
195+
196+
let img_conf = serde_json::from_str::<ImgConfigManifest>(&img_conf)
197+
.context("Failed to parse file as JSON")?;
198+
199+
Ok(img_conf)
200+
}
201+
184202
#[context("Getting composefs deployment metadata")]
185203
async fn boot_entry_from_composefs_deployment(
186204
storage: &Storage,
@@ -192,17 +210,7 @@ async fn boot_entry_from_composefs_deployment(
192210
let ostree_img_ref = OstreeImageReference::from_str(&img_name_from_config)?;
193211
let img_ref = ImageReference::from(ostree_img_ref);
194212

195-
let path = std::path::PathBuf::from(STATE_DIR_RELATIVE)
196-
.join(&verity)
197-
.join(format!("{verity}.imginfo"));
198-
199-
let img_conf = storage
200-
.physical_root
201-
.read_to_string(&path)
202-
.context("Failed to open imginfo file")?;
203-
204-
let img_conf: ImgConfigManifest =
205-
serde_json::from_str(&img_conf).context("Failed to parse imginfo file as JSON")?;
213+
let img_conf = get_imginfo(storage, &verity)?;
206214

207215
let image_digest = img_conf.manifest.config().digest().to_string();
208216
let architecture = img_conf.config.architecture().to_string();

crates/lib/src/bootc_composefs/update.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use composefs::{
88
use composefs_boot::BootOps;
99
use composefs_oci::image::create_filesystem;
1010
use fn_error_context::context;
11+
use ostree_ext::container::ManifestDiff;
1112

1213
use crate::{
1314
bootc_composefs::{
@@ -16,7 +17,7 @@ use crate::{
1617
service::start_finalize_stated_svc,
1718
state::write_composefs_state,
1819
status::{
19-
get_bootloader, get_composefs_status, get_container_manifest_and_config,
20+
get_bootloader, get_composefs_status, get_container_manifest_and_config, get_imginfo,
2021
ImgConfigManifest,
2122
},
2223
},
@@ -366,30 +367,9 @@ pub(crate) async fn upgrade_composefs(
366367
}
367368

368369
if opts.check {
369-
// TODO(Johan-Liebert1): If we have the previous, i.e. the current manifest with us then we can replace the
370-
// following with [`ostree_container::ManifestDiff::new`] which will be much cleaner
371-
for (idx, diff_id) in img_config.config.rootfs().diff_ids().iter().enumerate() {
372-
let diff_id = str_to_sha256digest(diff_id)?;
373-
374-
// we could use `check_stream` here but that will most probably take forever as it
375-
// usually takes ~3s to verify one single layer
376-
let have_layer = repo.has_stream(&diff_id)?;
377-
378-
if have_layer.is_none() {
379-
if idx >= img_config.manifest.layers().len() {
380-
anyhow::bail!("Length mismatch between rootfs diff layers and manifest layers");
381-
}
382-
383-
let layer = &img_config.manifest.layers()[idx];
384-
385-
println!(
386-
"Added layer: {}\tSize: {}",
387-
layer.digest(),
388-
layer.size().to_string()
389-
);
390-
}
391-
}
392-
370+
let current_manifest = get_imginfo(storage, &*composefs.cmdline.digest)?;
371+
let diff = ManifestDiff::new(&current_manifest.manifest, &img_config.manifest);
372+
diff.print();
393373
return Ok(());
394374
}
395375

0 commit comments

Comments
 (0)