From 2b8559f1134e0f8600983321645a853b63660ac0 Mon Sep 17 00:00:00 2001 From: Phoebus Date: Sun, 27 Sep 2026 17:22:55 -0700 Subject: [PATCH] fix(install): match VDB name-version dirs in finalize verify --- .../phoebus-installer/src/orchestrate.rs | 67 +++++++++++++------ 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/installer-rs/crates/phoebus-installer/src/orchestrate.rs b/installer-rs/crates/phoebus-installer/src/orchestrate.rs index 1dddffb..6cf8eb2 100644 --- a/installer-rs/crates/phoebus-installer/src/orchestrate.rs +++ b/installer-rs/crates/phoebus-installer/src/orchestrate.rs @@ -1185,31 +1185,25 @@ impl Installer { )); } } - for atom_dir in ["www-client/firefox-bin", "app-office/libreoffice-bin"] { - let vdb = std::path::Path::new(&self.exec.root) - .join("var/db/pkg") - .join(atom_dir); - let has_record = std::fs::read_dir(&vdb) - .map(|mut d| d.next().is_some()) - .unwrap_or(false); - if !has_record { + for (category, name) in [ + ("www-client", "firefox-bin"), + ("app-office", "libreoffice-bin"), + ] { + if !has_vdb_record(std::path::Path::new(&self.exec.root), category, name) { return Err(phoebus_executor::ExecError::operation( "finalize", "verify target", - format!("{atom_dir} has no package-database record in the target"), + format!("{category}/{name} has no package-database record in the target"), )); } } - for dup in ["var/db/pkg/app-text/calibre", "var/db/pkg/media-gfx/gimp"] { - let dup_path = std::path::Path::new(&self.exec.root).join(dup); - if let Ok(mut d) = std::fs::read_dir(&dup_path) { - if d.next().is_some() { - return Err(phoebus_executor::ExecError::operation( - "finalize", - "verify target", - format!("duplicate Portage copy under {dup}; Calibre/GIMP must be Flatpak-only"), - )); - } + for (category, name) in [("app-text", "calibre"), ("media-gfx", "gimp")] { + if has_vdb_record(std::path::Path::new(&self.exec.root), category, name) { + return Err(phoebus_executor::ExecError::operation( + "finalize", + "verify target", + format!("duplicate Portage copy under var/db/pkg/{category}/{name}; Calibre/GIMP must be Flatpak-only"), + )); } } if target.exists("usr/share/applications/phoebus-install.desktop") { @@ -1357,6 +1351,24 @@ fn dir_has_kernel(dir: &std::path::Path, depth: usize) -> bool { false } +/// Whether the target package database holds a record for `category/name`. +/// +/// The VDB layout is `var/db/pkg//-` (a directory +/// per installed version), so the check matches the `name-` prefix inside +/// the category directory. Matching a literal `category/name` directory +/// always fails: such a directory never exists, which once failed every +/// install at finalize time. +fn has_vdb_record(root: &std::path::Path, category: &str, name: &str) -> bool { + let dir = root.join("var/db/pkg").join(category); + let Ok(entries) = std::fs::read_dir(&dir) else { + return false; + }; + let prefix = format!("{name}-"); + entries + .flatten() + .any(|e| e.file_name().to_string_lossy().starts_with(prefix.as_str())) +} + #[cfg(test)] mod tests { use super::*; @@ -1452,6 +1464,23 @@ mod tests { assert!(err.contains("changed identity"), "{err}"); } + #[test] + fn vdb_records_match_name_version_dirs_not_literal_names() { + let root = tempfile::tempdir().unwrap(); + let root = root.path(); + // Real VDB layout: var/db/pkg//-. + let vdb = root.join("var/db/pkg/www-client/firefox-bin-156.0.1"); + std::fs::create_dir_all(&vdb).unwrap(); + assert!(has_vdb_record(root, "www-client", "firefox-bin")); + assert!(!has_vdb_record(root, "www-client", "chromium")); + assert!(!has_vdb_record(root, "app-office", "libreoffice-bin")); + // A literal `category/name` directory is NOT a record (the old + // finalize check matched this and failed every install). + let literal = root.join("var/db/pkg/app-text/calibre"); + std::fs::create_dir_all(&literal).unwrap(); + assert!(!has_vdb_record(root, "app-text", "calibre")); + } + #[test] fn target_kernel_detection_handles_the_bls_layout() { let root = tempfile::tempdir().unwrap();