From fd86d1dc3ed86dd60b1660c1c4f73e38c24ce025 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 22 Nov 2024 15:28:24 -0500 Subject: [PATCH] install: Factor out helper to create aleph version Prep for the anaconda install completion work. Signed-off-by: Colin Walters --- lib/src/install.rs | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/src/install.rs b/lib/src/install.rs index 98857edf..00a07c21 100644 --- a/lib/src/install.rs +++ b/lib/src/install.rs @@ -495,6 +495,32 @@ impl FromStr for MountSpec { } } +impl InstallAleph { + #[context("Creating aleph data")] + pub(crate) fn new( + src_imageref: &ostree_container::OstreeImageReference, + imgstate: &ostree_container::store::LayeredImageState, + selinux_state: &SELinuxFinalState, + ) -> Result { + let uname = rustix::system::uname(); + let labels = crate::status::labels_of_config(&imgstate.configuration); + let timestamp = labels + .and_then(|l| { + l.get(oci_spec::image::ANNOTATION_CREATED) + .map(|s| s.as_str()) + }) + .and_then(crate::status::try_deserialize_timestamp); + let r = InstallAleph { + image: src_imageref.imgref.name.clone(), + version: imgstate.version().as_ref().map(|s| s.to_string()), + timestamp, + kernel: uname.release().to_str()?.to_string(), + selinux: selinux_state.to_aleph().to_string(), + }; + Ok(r) + } +} + impl SourceInfo { // Inspect container information and convert it to an ostree image reference // that pulls from containers-storage. @@ -842,23 +868,7 @@ async fn install_container( osconfig::inject_root_ssh_authorized_keys(&root, sepolicy, contents)?; } - let uname = rustix::system::uname(); - - let labels = crate::status::labels_of_config(&imgstate.configuration); - let timestamp = labels - .and_then(|l| { - l.get(oci_spec::image::ANNOTATION_CREATED) - .map(|s| s.as_str()) - }) - .and_then(crate::status::try_deserialize_timestamp); - let aleph = InstallAleph { - image: src_imageref.imgref.name.clone(), - version: imgstate.version().as_ref().map(|s| s.to_string()), - timestamp, - kernel: uname.release().to_str()?.to_string(), - selinux: state.selinux_state.to_aleph().to_string(), - }; - + let aleph = InstallAleph::new(&src_imageref, &imgstate, &state.selinux_state)?; Ok((deployment, aleph)) }