From a99b6ad216bd9add8bb379fad72cd52308d4835f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 6 Nov 2024 11:30:55 -0500 Subject: [PATCH] Don't hardcode usr/share/rpm We don't need this on modern Fedora anymore for example. If we detect the sysimage path, then just use it. --- src/ostreeutil.rs | 18 +++++++++++------- src/packagesystem.rs | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ostreeutil.rs b/src/ostreeutil.rs index e38a9d9f..c4212199 100644 --- a/src/ostreeutil.rs +++ b/src/ostreeutil.rs @@ -6,20 +6,24 @@ use std::path::Path; +use anyhow::Result; + /// https://github.com/coreos/rpm-ostree/pull/969/commits/dc0e8db5bd92e1f478a0763d1a02b48e57022b59 #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] pub(crate) const BOOT_PREFIX: &str = "usr/lib/ostree-boot"; +const LEGACY_RPMOSTREE_DBPATH: &str = "usr/share/rpm"; +const SYSIMAGE_RPM_DBPATH: &str = "usr/lib/sysimage/rpm"; -pub(crate) fn rpm_cmd>(sysroot: P) -> std::process::Command { +pub(crate) fn rpm_cmd>(sysroot: P) -> Result { + let mut c = std::process::Command::new("rpm"); let sysroot = sysroot.as_ref(); - let dbpath = sysroot.join("usr/share/rpm"); - let dbpath_arg = { + let modern_dbpath = sysroot.join(SYSIMAGE_RPM_DBPATH); + if !modern_dbpath.try_exists()? { + let dbpath = sysroot.join(LEGACY_RPMOSTREE_DBPATH); let mut s = std::ffi::OsString::new(); s.push("--dbpath="); s.push(dbpath.as_os_str()); - s + c.arg(s); }; - let mut c = std::process::Command::new("rpm"); - c.arg(&dbpath_arg); - c + Ok(c) } diff --git a/src/packagesystem.rs b/src/packagesystem.rs index 2536a93c..8c5d1f7e 100644 --- a/src/packagesystem.rs +++ b/src/packagesystem.rs @@ -52,7 +52,7 @@ pub(crate) fn query_files( where T: AsRef, { - let mut c = ostreeutil::rpm_cmd(sysroot_path); + let mut c = ostreeutil::rpm_cmd(sysroot_path)?; c.args(["-q", "--queryformat", "%{nevra},%{buildtime} ", "-f"]); for arg in paths { c.arg(arg.as_ref());