From d4f2a174e267b96ca57ae7b1fbb19ea20e4a86a9 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Sun, 9 Jun 2024 03:42:25 +0100 Subject: [PATCH] blsctl: Force `Into` for Legacykernel to interop Signed-off-by: Ikey Doherty --- blsctl/src/legacy.rs | 50 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/blsctl/src/legacy.rs b/blsctl/src/legacy.rs index 295499d..07e97fb 100644 --- a/blsctl/src/legacy.rs +++ b/blsctl/src/legacy.rs @@ -4,18 +4,40 @@ //! Support for legacy schema (CBM days) kernel packaging -use std::{fs, path::Path}; +use std::{ + fs, + path::{Path, PathBuf}, +}; + +use blsforme::kernel::{AuxilliaryFile, AuxilliaryKind, Kernel}; /// A discovery type: Will not be public forever. #[derive(Debug)] -pub struct LegacyKernel { +struct LegacyKernel { version: String, + path: PathBuf, variant: String, release: u64, + aux: Vec, +} + +impl From for Kernel { + fn from(val: LegacyKernel) -> Self { + let (initrd, extras) = val + .aux + .into_iter() + .partition(|a| matches!(a.kind, AuxilliaryKind::InitRD)); + Kernel { + version: val.version, + image: val.path, + initrd, + extras, + } + } } /// Why oh why did we invent this poxy scheme -pub fn discover_kernels_legacy(namespace: &str, root: impl AsRef) -> color_eyre::Result> { +pub fn discover_kernels_legacy(namespace: &str, root: impl AsRef) -> color_eyre::Result> { let root = root.as_ref().join("usr").join("lib").join("kernel"); let mut initial_kernels = vec![]; @@ -33,9 +55,11 @@ pub fn discover_kernels_legacy(namespace: &str, root: impl AsRef) -> color if let Some((version, release)) = version.rfind('-').map(|i| version.split_at(i)) { log::trace!("discovered vmlinuz: {file_name}"); initial_kernels.push(LegacyKernel { + path: item.path(), version: version.into(), variant: variant.into(), release: release.chars().skip(1).collect::().parse::()?, + aux: vec![], }) } } @@ -45,7 +69,7 @@ pub fn discover_kernels_legacy(namespace: &str, root: impl AsRef) -> color initial_kernels.sort_by_key(|k| k.release); initial_kernels.reverse(); - for kernel in initial_kernels.iter() { + for kernel in initial_kernels.iter_mut() { let cmdline = root.join(format!( "cmdline-{}-{}.{}", &kernel.version, kernel.release, &kernel.variant @@ -65,17 +89,33 @@ pub fn discover_kernels_legacy(namespace: &str, root: impl AsRef) -> color if cmdline.exists() { log::debug!("cmdline: {cmdline:?}"); + kernel.aux.push(AuxilliaryFile { + path: cmdline, + kind: AuxilliaryKind::Cmdline, + }) } if initrd.exists() { log::debug!("initrd: {initrd:?}"); + kernel.aux.push(AuxilliaryFile { + path: initrd, + kind: AuxilliaryKind::InitRD, + }) } if config.exists() { log::debug!("config: {config:?}"); + kernel.aux.push(AuxilliaryFile { + path: config, + kind: AuxilliaryKind::Config, + }) } if sysmap.exists() { log::debug!("sysmap: {sysmap:?}"); + kernel.aux.push(AuxilliaryFile { + path: sysmap, + kind: AuxilliaryKind::SystemMap, + }) } } - Ok(initial_kernels) + Ok(initial_kernels.into_iter().map(|m| m.into()).collect()) }