fix(install): match VDB name-version dirs in finalize verify
This commit is contained in:
parent
de2d7918c3
commit
2b8559f113
1 changed files with 48 additions and 19 deletions
|
|
@ -1185,33 +1185,27 @@ impl Installer {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for atom_dir in ["www-client/firefox-bin", "app-office/libreoffice-bin"] {
|
for (category, name) in [
|
||||||
let vdb = std::path::Path::new(&self.exec.root)
|
("www-client", "firefox-bin"),
|
||||||
.join("var/db/pkg")
|
("app-office", "libreoffice-bin"),
|
||||||
.join(atom_dir);
|
] {
|
||||||
let has_record = std::fs::read_dir(&vdb)
|
if !has_vdb_record(std::path::Path::new(&self.exec.root), category, name) {
|
||||||
.map(|mut d| d.next().is_some())
|
|
||||||
.unwrap_or(false);
|
|
||||||
if !has_record {
|
|
||||||
return Err(phoebus_executor::ExecError::operation(
|
return Err(phoebus_executor::ExecError::operation(
|
||||||
"finalize",
|
"finalize",
|
||||||
"verify target",
|
"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"] {
|
for (category, name) in [("app-text", "calibre"), ("media-gfx", "gimp")] {
|
||||||
let dup_path = std::path::Path::new(&self.exec.root).join(dup);
|
if has_vdb_record(std::path::Path::new(&self.exec.root), category, name) {
|
||||||
if let Ok(mut d) = std::fs::read_dir(&dup_path) {
|
|
||||||
if d.next().is_some() {
|
|
||||||
return Err(phoebus_executor::ExecError::operation(
|
return Err(phoebus_executor::ExecError::operation(
|
||||||
"finalize",
|
"finalize",
|
||||||
"verify target",
|
"verify target",
|
||||||
format!("duplicate Portage copy under {dup}; Calibre/GIMP must be Flatpak-only"),
|
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") {
|
if target.exists("usr/share/applications/phoebus-install.desktop") {
|
||||||
return Err(phoebus_executor::ExecError::operation(
|
return Err(phoebus_executor::ExecError::operation(
|
||||||
"finalize",
|
"finalize",
|
||||||
|
|
@ -1357,6 +1351,24 @@ fn dir_has_kernel(dir: &std::path::Path, depth: usize) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the target package database holds a record for `category/name`.
|
||||||
|
///
|
||||||
|
/// The VDB layout is `var/db/pkg/<category>/<name>-<version>` (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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
@ -1452,6 +1464,23 @@ mod tests {
|
||||||
assert!(err.contains("changed identity"), "{err}");
|
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/<category>/<name>-<version>.
|
||||||
|
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]
|
#[test]
|
||||||
fn target_kernel_detection_handles_the_bls_layout() {
|
fn target_kernel_detection_handles_the_bls_layout() {
|
||||||
let root = tempfile::tempdir().unwrap();
|
let root = tempfile::tempdir().unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue