Skip to content

Commit a9979e9

Browse files
authored
Merge pull request #1136 from cgwalters/cfs-lint-opt
lint: Split composefs into separate warning lint
2 parents 5309d5b + 406bfe3 commit a9979e9

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

lib/src/lints.rs

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,40 @@ fn check_utf8(dir: &Dir) -> LintResult {
360360
lint_ok()
361361
}
362362

363+
fn check_prepareroot_composefs_norecurse(dir: &Dir) -> LintResult {
364+
let path = ostree_ext::ostree_prepareroot::CONF_PATH;
365+
let Some(config) = ostree_prepareroot::load_config_from_root(dir)? else {
366+
return lint_err(format!("{path} is not present to enable composefs"));
367+
};
368+
if !ostree_prepareroot::overlayfs_enabled_in_config(&config)? {
369+
return lint_err(format!("{path} does not have composefs enabled"));
370+
}
371+
lint_ok()
372+
}
373+
374+
#[distributed_slice(LINTS)]
375+
static LINT_COMPOSEFS: Lint = Lint::new_warning(
376+
"baseimage-composefs",
377+
indoc! { r#"
378+
Check that composefs is enabled for ostree. More in
379+
<https://ostreedev.github.io/ostree/composefs/>.
380+
"#},
381+
check_composefs,
382+
);
383+
fn check_composefs(dir: &Dir) -> LintResult {
384+
if let Err(e) = check_prepareroot_composefs_norecurse(dir)? {
385+
return Ok(Err(e));
386+
}
387+
// If we have our own documentation with the expected root contents
388+
// embedded, then check that too! Mostly just because recursion is fun.
389+
if let Some(dir) = dir.open_dir_optional(BASEIMAGE_REF)? {
390+
if let Err(e) = check_prepareroot_composefs_norecurse(&dir)? {
391+
return Ok(Err(e));
392+
}
393+
}
394+
lint_ok()
395+
}
396+
363397
/// Check for a few files and directories we expect in the base image.
364398
fn check_baseimage_root_norecurse(dir: &Dir) -> LintResult {
365399
// Check /sysroot
@@ -380,12 +414,7 @@ fn check_baseimage_root_norecurse(dir: &Dir) -> LintResult {
380414
let link = dir.read_link_contents("ostree")?;
381415
let expected = "sysroot/ostree";
382416
if link.as_os_str().as_bytes() != expected.as_bytes() {
383-
return lint_err("Expected /ostree -> {expected}, not {link:?}");
384-
}
385-
386-
let config = ostree_prepareroot::require_config_from_root(dir)?;
387-
if !ostree_prepareroot::overlayfs_enabled_in_config(&config)? {
388-
return lint_err("{prepareroot_path} does not have composefs enabled");
417+
return lint_err(format!("Expected /ostree -> {expected}, not {link:?}"));
389418
}
390419

391420
lint_ok()
@@ -860,6 +889,26 @@ mod tests {
860889
Ok(())
861890
}
862891

892+
#[test]
893+
fn test_composefs() -> Result<()> {
894+
let td = fixture()?;
895+
896+
// An empty root should fail our test
897+
assert!(check_composefs(&td).unwrap().is_err());
898+
899+
drop(td);
900+
let td = passing_fixture()?;
901+
check_baseimage_root(&td).unwrap().unwrap();
902+
903+
td.write(
904+
"usr/lib/ostree/prepare-root.conf",
905+
b"[composefs]\nenabled = false",
906+
)?;
907+
assert!(check_composefs(&td).unwrap().is_err());
908+
909+
Ok(())
910+
}
911+
863912
#[test]
864913
fn test_buildah_injected() -> Result<()> {
865914
let td = fixture()?;

ostree-ext/src/ostree_prepareroot.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use crate::keyfileext::KeyFileExt;
1818
use crate::ostree_manual;
1919
use crate::utils::ResultExt;
2020

21-
pub(crate) const CONF_PATH: &str = "ostree/prepare-root.conf";
21+
/// The relative path to ostree-prepare-root's config.
22+
pub const CONF_PATH: &str = "ostree/prepare-root.conf";
2223

2324
pub(crate) fn load_config(root: &ostree::RepoFile) -> Result<Option<glib::KeyFile>> {
2425
let cancellable = gio::Cancellable::NONE;

0 commit comments

Comments
 (0)