From a4ebc2e580297ca0541197092704133bee512215 Mon Sep 17 00:00:00 2001 From: Steven Presti Date: Thu, 7 Mar 2024 10:13:40 -0500 Subject: [PATCH] cli: add build-lint add simple lint to check that we only have one kernel in image. fixes: #216 Co-authored-by: Joseph Marrero Co-authored-by: Huijing Hei --- lib/src/cli.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 345e2e69c..fc1e33c99 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -12,6 +12,7 @@ use ostree_container::store::PrepareResult; use ostree_ext::container as ostree_container; use ostree_ext::keyfileext::KeyFileExt; use ostree_ext::ostree; +use tracing::field::debug; use std::ffi::OsString; use std::io::Seek; use std::os::unix::process::CommandExt; @@ -213,7 +214,7 @@ pub(crate) enum Opt { #[cfg(feature = "install")] Install(InstallOpts), /// Validate non supported files are not present. - BuildCommit, + BuildLint, /// Execute the given command in the host mount namespace #[cfg(feature = "install")] #[clap(hide = true)] @@ -515,12 +516,24 @@ async fn usroverlay() -> Result<()> { } /// Implementation of `bootc build commit` -async fn commit() -> Result<()> { - // This is just a pass-through today. At some point we may diverge from ostree-ext. - return Err(Command::new("ostree") - .args(["container", "commit"]) - .exec() - .into()); +/// async fn lint() -> Result<()> { +fn lint() -> Result<()> { + // TODO: Check if 1 or more folder under the /lib/modules/ directory + println!("Checking if we are in the container"); + if ostree_ext::container_utils::is_ostree_container()? { + let modules_path = cap_std::fs::Dir::open_ambient_dir("lib/modules", cap_std::ambient_authority())?; + for entry in modules_path.entries()? { + let dir = entry?; + let fileName= dir.file_name(); + debug(fileName); + + } + return Ok(()); + } + anyhow::bail!( + "Not in a ostree container, this command only verifies ostree containers." + ); + } /// Parse the provided arguments and execute. @@ -540,7 +553,7 @@ async fn run_from_opt(opt: Opt) -> Result<()> { Opt::Switch(opts) => switch(opts).await, Opt::Edit(opts) => edit(opts).await, Opt::UsrOverlay => usroverlay().await, - Opt::BuildCommit => commit().await, + Opt::BuildLint => lint(), #[cfg(feature = "install")] Opt::Install(opts) => match opts { InstallOpts::ToDisk(opts) => crate::install::install_to_disk(opts).await,