From f18505aee988c401360086b6109d2cc82e6acfea Mon Sep 17 00:00:00 2001 From: Phoebus Date: Tue, 29 Sep 2026 07:34:51 -0700 Subject: [PATCH] fix(kernel): match the VDB record exactly and use loader/entries for BLS --- .../crates/phoebus-executor/src/actions.rs | 11 ++++- .../crates/phoebus-executor/src/kernel.rs | 46 +++++++++++++++---- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/installer-rs/crates/phoebus-executor/src/actions.rs b/installer-rs/crates/phoebus-executor/src/actions.rs index c4596e0..5872f5a 100644 --- a/installer-rs/crates/phoebus-executor/src/actions.rs +++ b/installer-rs/crates/phoebus-executor/src/actions.rs @@ -251,7 +251,16 @@ fn vdb_has_atom(root: &Path, atom: &str) -> bool { }; entries.flatten().any(|e| { let name = e.file_name().to_string_lossy().to_string(); - name == package || name.starts_with(&format!("{package}-")) + if name == package { + return true; + } + match name.strip_prefix(&format!("{package}-")) { + // A Gentoo version begins with a digit. Requiring it stops a + // sibling package (`gentoo-kernel-bin-…`) from matching the + // prefix `gentoo-kernel-…`. + Some(rest) => rest.chars().next().is_some_and(|c| c.is_ascii_digit()), + None => false, + } }) } diff --git a/installer-rs/crates/phoebus-executor/src/kernel.rs b/installer-rs/crates/phoebus-executor/src/kernel.rs index c71aa6b..2e10c8f 100644 --- a/installer-rs/crates/phoebus-executor/src/kernel.rs +++ b/installer-rs/crates/phoebus-executor/src/kernel.rs @@ -198,7 +198,16 @@ fn vdb_has_atom(root: &Path, atom: &str) -> bool { }; entries.flatten().any(|e| { let name = e.file_name().to_string_lossy().to_string(); - name == package || name.starts_with(&format!("{package}-")) + if name == package { + return true; + } + match name.strip_prefix(&format!("{package}-")) { + // A Gentoo version begins with a digit. Requiring it stops a + // sibling package (`gentoo-kernel-bin-…`) from matching the + // prefix `gentoo-kernel-…`. + Some(rest) => rest.chars().next().is_some_and(|c| c.is_ascii_digit()), + None => false, + } }) } @@ -206,11 +215,13 @@ fn vdb_has_atom(root: &Path, atom: &str) -> bool { /// tuned). Returns the new entry file name. Never rewrites the default loader /// selection. fn source_kernel_bls_entry(root: &Path, choice: KernelChoice) -> Result { - let entries = root.join("efi/EFI/Linux"); + // systemd-boot BLS entries live in `$ESP/loader/entries/*.conf` (the same + // directory `boot.rs` writes). `EFI/Linux` is for UKIs, which are deferred. + let entries = root.join("efi/loader/entries"); let entries = if entries.is_dir() { entries } else { - root.join("boot/EFI/Linux") + root.join("boot/loader/entries") }; let Ok(dir) = std::fs::read_dir(&entries) else { return Err(ExecError::operation( @@ -356,9 +367,9 @@ mod tests { std::fs::create_dir_all(root.join(dir)).unwrap(); } // Fixture boot layout: one default entry plus the loader config. - std::fs::create_dir_all(root.join("efi/EFI/Linux")).unwrap(); + std::fs::create_dir_all(root.join("efi/loader/entries")).unwrap(); std::fs::write( - root.join("efi/EFI/Linux/phoebus.conf"), + root.join("efi/loader/entries/phoebus.conf"), "title Phoebus\nlinux /vmlinuz-6.12.32\noptions root=/dev/mapper/cryptroot\n", ) .unwrap(); @@ -372,7 +383,8 @@ mod tests { let out = build_tuned_kernel(&exec, root, true).unwrap(); assert!(out.contains("separate boot entry"), "{out}"); // The new entry exists and derives from the current one. - let tuned = std::fs::read_to_string(root.join("efi/EFI/Linux/phoebus-tuned.conf")).unwrap(); + let tuned = + std::fs::read_to_string(root.join("efi/loader/entries/phoebus-tuned.conf")).unwrap(); assert!(tuned.contains("linux /vmlinuz-6.12.32"), "{tuned}"); // The default was NOT switched: no test boot happened in this // context, so the generic kernel stays the default. @@ -390,6 +402,22 @@ mod tests { assert_only_generic_kernel(&["sys-kernel/gentoo-kernel-bin".to_string()]); } + #[test] + fn vdb_match_does_not_confuse_sibling_packages() { + let runner = RecordingRunner::new(); + let exec = make_exec(runner); + let root = Path::new(&exec.root); + std::fs::create_dir_all(root.join("var/db/pkg/sys-kernel/gentoo-kernel-bin-6.18.50")) + .unwrap(); + assert!(vdb_has_atom(root, "sys-kernel/gentoo-kernel-bin")); + assert!( + !vdb_has_atom(root, "sys-kernel/gentoo-kernel"), + "gentoo-kernel-bin must not satisfy the gentoo-kernel atom" + ); + std::fs::create_dir_all(root.join("var/db/pkg/sys-kernel/gentoo-kernel-6.18.50")).unwrap(); + assert!(vdb_has_atom(root, "sys-kernel/gentoo-kernel")); + } + #[test] fn balanced_build_refuses_without_the_known_good_fallback() { let runner = RecordingRunner::new(); @@ -410,9 +438,9 @@ mod tests { ] { std::fs::create_dir_all(root.join(dir)).unwrap(); } - std::fs::create_dir_all(root.join("efi/EFI/Linux")).unwrap(); + std::fs::create_dir_all(root.join("efi/loader/entries")).unwrap(); std::fs::write( - root.join("efi/EFI/Linux/phoebus.conf"), + root.join("efi/loader/entries/phoebus.conf"), "title Phoebus\nlinux /vmlinuz-6.12.32\noptions root=/dev/mapper/cryptroot\n", ) .unwrap(); @@ -426,7 +454,7 @@ mod tests { let out = build_balanced_kernel(&exec, root, false).unwrap(); assert!(out.contains("balanced source kernel"), "{out}"); let entry = - std::fs::read_to_string(root.join("efi/EFI/Linux/phoebus-balanced.conf")).unwrap(); + std::fs::read_to_string(root.join("efi/loader/entries/phoebus-balanced.conf")).unwrap(); assert!(entry.contains("linux /vmlinuz-6.12.32"), "{entry}"); assert!(entry.contains("balanced"), "{entry}"); // The balanced fragment carries broad hot-plug coverage, not tuning.