diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 56c6b5f10..cb958eb7e 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -286,24 +286,29 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> { let repo = &sysroot.repo(); let booted_deployment = &sysroot.require_booted_deployment()?; let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?; - // SAFETY: There must be a status if we have a booted deployment - let status = host.status.unwrap(); let imgref = host.spec.image.as_ref(); // If there's no specified image, let's be nice and check if the booted system is using rpm-ostree - if imgref.is_none() && status.booted.as_ref().map_or(false, |b| b.incompatible) { + if imgref.is_none() + && host + .status + .booted + .as_ref() + .map_or(false, |b| b.incompatible) + { return Err(anyhow::anyhow!( "Booted deployment contains local rpm-ostree modifications; cannot upgrade via bootc" )); } let spec = RequiredHostSpec::from_spec(&host.spec)?; - let booted_image = status + let booted_image = host + .status .booted .map(|b| b.query_image(repo)) .transpose()? .flatten(); let imgref = imgref.ok_or_else(|| anyhow::anyhow!("No image source specified"))?; // Find the currently queued digest, if any before we pull - let staged = status.staged.as_ref(); + let staged = host.status.staged.as_ref(); let staged_image = staged.as_ref().and_then(|s| s.image.as_ref()); let mut changed = false; if opts.check { diff --git a/lib/src/privtests.rs b/lib/src/privtests.rs index ea541d2ea..97c07a046 100644 --- a/lib/src/privtests.rs +++ b/lib/src/privtests.rs @@ -103,8 +103,7 @@ pub(crate) fn impl_run_container() -> Result<()> { assert!(ostree_ext::container_utils::is_ostree_container()?); let sh = Shell::new()?; let host: Host = serde_yaml::from_str(&cmd!(sh, "bootc status").read()?)?; - let status = host.status.unwrap(); - assert!(status.is_container); + assert!(host.status.is_container); for c in ["upgrade", "update"] { let o = Command::new("bootc").arg(c).output()?; let st = o.status; diff --git a/lib/src/spec.rs b/lib/src/spec.rs index 577924e40..2e7e53dc2 100644 --- a/lib/src/spec.rs +++ b/lib/src/spec.rs @@ -19,7 +19,8 @@ pub struct Host { #[serde(default)] pub spec: HostSpec, /// The status - pub status: Option, + #[serde(default)] + pub status: HostStatus, } #[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)] @@ -121,7 +122,7 @@ impl Host { metadata, }, spec, - status: None, + status: Default::default(), } } } diff --git a/lib/src/status.rs b/lib/src/status.rs index 4442a4666..b8e6e1bee 100644 --- a/lib/src/status.rs +++ b/lib/src/status.rs @@ -227,12 +227,12 @@ pub(crate) fn get_status( }) .unwrap_or_default(); let mut host = Host::new(OBJECT_NAME, spec); - host.status = Some(HostStatus { + host.status = HostStatus { staged, booted, rollback, is_container, - }); + }; Ok((deployments, host)) } @@ -244,7 +244,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> { ..Default::default() }; let mut r = Host::new(OBJECT_NAME, HostSpec { image: None }); - r.status = Some(status); + r.status = status; r } else { let sysroot = super::cli::get_locked_sysroot().await?;