Skip to content

Commit 59d6b11

Browse files
committed
lints: Ignore /boot/EFI
See containers/composefs-rs#131 Signed-off-by: Colin Walters <[email protected]>
1 parent cae0e64 commit 59d6b11

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use std::ffi::OsStr;
12
use std::fs::create_dir_all;
23
use std::io::Write;
34
use std::path::Path;
4-
use std::ffi::OsStr;
55

66
use anyhow::{anyhow, Context, Result};
77
use bootc_blockdev::find_parent_devices;
@@ -51,7 +51,7 @@ use crate::install::{RootSetup, State};
5151
/// Contains the EFP's filesystem UUID. Used by grub
5252
pub(crate) const EFI_UUID_FILE: &str = "efiuuid.cfg";
5353
/// The EFI Linux directory
54-
const EFI_LINUX: &str = "EFI/Linux";
54+
pub(crate) const EFI_LINUX: &str = "EFI/Linux";
5555

5656
/// Timeout for systemd-boot bootloader menu
5757
const SYSTEMD_TIMEOUT: &str = "timeout 5";
@@ -1024,8 +1024,8 @@ pub(crate) fn setup_composefs_boot(
10241024

10251025
#[cfg(test)]
10261026
mod tests {
1027-
use cap_std_ext::cap_std;
10281027
use super::*;
1028+
use cap_std_ext::cap_std;
10291029

10301030
#[test]
10311031
fn test_root_has_uki() -> Result<()> {
@@ -1051,4 +1051,4 @@ mod tests {
10511051

10521052
Ok(())
10531053
}
1054-
}
1054+
}

crates/lib/src/lints.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ use linkme::distributed_slice;
2727
use ostree_ext::ostree_prepareroot;
2828
use serde::Serialize;
2929

30+
use crate::bootc_composefs::boot::EFI_LINUX;
31+
3032
/// Reference to embedded default baseimage content that should exist.
3133
const BASEIMAGE_REF: &str = "usr/share/doc/bootc/baseimage/base";
3234
// https://systemd.io/API_FILE_SYSTEMS/ with /var added for us
@@ -758,14 +760,24 @@ fn check_boot(root: &Dir, config: &LintExecutionConfig) -> LintResult {
758760
};
759761

760762
// First collect all entries to determine if the directory is empty
761-
let entries: Result<Vec<_>, _> = d.entries()?.collect();
762-
let entries = entries?;
763+
let entries: Result<BTreeSet<_>, _> = d
764+
.entries()?
765+
.into_iter()
766+
.map(|v| {
767+
let v = v?;
768+
anyhow::Ok(v.file_name())
769+
})
770+
.collect();
771+
let mut entries = entries?;
772+
// Work around https://github.com/containers/composefs-rs/issues/131
773+
let efidir = Utf8Path::new(EFI_LINUX)
774+
.parent()
775+
.map(|b| b.as_std_path())
776+
.unwrap();
777+
entries.remove(efidir.as_os_str());
763778
if entries.is_empty() {
764779
return lint_ok();
765780
}
766-
// Gather sorted filenames
767-
let mut entries = entries.iter().map(|v| v.file_name()).collect::<Vec<_>>();
768-
entries.sort();
769781

770782
let header = "Found non-empty /boot";
771783
let items = entries.iter().map(PathQuotedDisplay::new);
@@ -973,6 +985,12 @@ mod tests {
973985
let root = &passing_fixture()?;
974986
let config = &LintExecutionConfig::default();
975987
check_boot(&root, config).unwrap().unwrap();
988+
989+
// Verify creating EFI doesn't error
990+
root.create_dir_all("EFI/Linux")?;
991+
root.write("EFI/Linux/foo.efi", b"some dummy efi")?;
992+
check_boot(&root, config).unwrap().unwrap();
993+
976994
root.create_dir("boot/somesubdir")?;
977995
let Err(e) = check_boot(&root, config).unwrap() else {
978996
unreachable!()

0 commit comments

Comments
 (0)