Skip to content

Commit 406bfe3

Browse files
committed
lint: Split composefs into separate warning lint
We do want to support using bootc without composefs for now. Closes: #1135 Signed-off-by: Colin Walters <[email protected]>
1 parent b305a05 commit 406bfe3

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

lib/src/lints.rs

Lines changed: 54 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
@@ -383,12 +417,6 @@ fn check_baseimage_root_norecurse(dir: &Dir) -> LintResult {
383417
return lint_err(format!("Expected /ostree -> {expected}, not {link:?}"));
384418
}
385419

386-
let config = ostree_prepareroot::require_config_from_root(dir)?;
387-
if !ostree_prepareroot::overlayfs_enabled_in_config(&config)? {
388-
let path = ostree_ext::ostree_prepareroot::CONF_PATH;
389-
return lint_err(format!("{path} does not have composefs enabled"));
390-
}
391-
392420
lint_ok()
393421
}
394422

@@ -861,6 +889,26 @@ mod tests {
861889
Ok(())
862890
}
863891

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+
864912
#[test]
865913
fn test_buildah_injected() -> Result<()> {
866914
let td = fixture()?;

0 commit comments

Comments
 (0)