Skip to content

Commit 5e0df36

Browse files
authored
Merge pull request #1075 from cgwalters/lint-more3
lint: Check for /boot
2 parents 0487bb9 + 1a8652c commit 5e0df36

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

lib/src/lints.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ const LINTS: &[Lint] = &[
139139
sensitive build system information.
140140
"#},
141141
},
142+
Lint {
143+
name: "nonempty-boot",
144+
ty: LintType::Warning,
145+
f: check_boot,
146+
description: indoc! { r#"
147+
The `/boot` directory should be present, but empty. The kernel
148+
content should be in /usr/lib/modules instead in the container image.
149+
Any content here in the container image will be masked at runtime.
150+
"#},
151+
},
142152
];
143153

144154
pub(crate) fn lint_list(output: impl std::io::Write) -> Result<()> {
@@ -351,6 +361,25 @@ fn check_varlog(root: &Dir) -> LintResult {
351361
lint_err(format!("Found non-empty logfile: {first}{others}"))
352362
}
353363

364+
fn check_boot(root: &Dir) -> LintResult {
365+
let Some(d) = root.open_dir_optional("boot")? else {
366+
return lint_err(format!("Missing /boot directory"));
367+
};
368+
let mut entries = d.entries()?;
369+
let Some(ent) = entries.next() else {
370+
return lint_ok();
371+
};
372+
let ent = ent?;
373+
let first = ent.file_name();
374+
let others = entries.count();
375+
let others = if others > 0 {
376+
format!(" (and {others} more)")
377+
} else {
378+
"".into()
379+
};
380+
lint_err(format!("Found non-empty /boot: {first:?}{others}"))
381+
}
382+
354383
#[cfg(test)]
355384
mod tests {
356385
use super::*;
@@ -365,6 +394,7 @@ mod tests {
365394
root.create_dir_all("usr/lib/modules/5.7.2")?;
366395
root.write("usr/lib/modules/5.7.2/vmlinuz", "vmlinuz")?;
367396

397+
root.create_dir("boot")?;
368398
root.create_dir("sysroot")?;
369399
root.symlink_contents("sysroot/ostree", "ostree")?;
370400

@@ -473,6 +503,19 @@ mod tests {
473503
Ok(())
474504
}
475505

506+
#[test]
507+
fn test_boot() -> Result<()> {
508+
let root = &passing_fixture()?;
509+
check_boot(&root).unwrap().unwrap();
510+
root.create_dir("boot/somesubdir")?;
511+
let Err(e) = check_boot(&root).unwrap() else {
512+
unreachable!()
513+
};
514+
assert!(e.to_string().contains("somesubdir"));
515+
516+
Ok(())
517+
}
518+
476519
#[test]
477520
fn test_non_utf8() {
478521
use std::{ffi::OsStr, os::unix::ffi::OsStrExt};

0 commit comments

Comments
 (0)