Skip to content

Commit

Permalink
Don't hardcode usr/share/rpm
Browse files Browse the repository at this point in the history
We don't need this on modern Fedora anymore for example.
If we detect the sysimage path, then just use it.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Nov 21, 2024
1 parent 0aedf55 commit e22d3bb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions src/ostreeutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@

use std::path::Path;

use anyhow::Result;
use log::debug;

/// 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<P: AsRef<Path>>(sysroot: P) -> std::process::Command {
pub(crate) fn rpm_cmd<P: AsRef<Path>>(sysroot: P) -> Result<std::process::Command> {
let mut c = std::process::Command::new("rpm");
let sysroot = sysroot.as_ref();
let dbpath = sysroot.join("usr/share/rpm");
let dbpath_arg = {
for dbpath in [SYSIMAGE_RPM_DBPATH, LEGACY_RPMOSTREE_DBPATH] {
let dbpath = sysroot.join(dbpath);
if !dbpath.try_exists()? {
continue;
}
let mut s = std::ffi::OsString::new();
s.push("--dbpath=");
s.push(dbpath.as_os_str());
s
};
let mut c = std::process::Command::new("rpm");
c.arg(&dbpath_arg);
c
c.arg(s);
return Ok(c);
}
debug!("Failed to find well-known rpmdb path");
Ok(c)
}
2 changes: 1 addition & 1 deletion src/packagesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) fn query_files<T>(
where
T: AsRef<Path>,
{
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());
Expand Down

0 comments on commit e22d3bb

Please sign in to comment.