Skip to content

Commit 229460a

Browse files
Johan-Liebert1cgwalters
authored andcommitted
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 <pragyanpoudyal41999@gmail.com>
1 parent c006368 commit 229460a

2 files changed

Lines changed: 24 additions & 36 deletions

File tree

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
},
@@ -371,30 +372,9 @@ pub(crate) async fn upgrade_composefs(
371372
}
372373

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

0 commit comments

Comments
 (0)