Skip to content

Commit

Permalink
Add /usr/lib/rpm/macros.d/macros.rpm-ostree to set %_dbpath to /usr/s…
Browse files Browse the repository at this point in the history
…hare/rpm

We trigger a librpm macro file load in many of our paths. Since the
default value shipped by rpm's macro file sets `_dbpath` to
`/var/lib/rpm`, we have to explicitly set that back to `/usr/share/rpm`
in those paths.

This became more problematic recently with libsolv v0.7.17 which fully
keys off of `_dbpath` to find the rpmdb path to load:

openSUSE/libsolv@04d4d03

And it's not technically wrong; we really should make that macro not
lie. This is what this patch does by injecting an RPM macro file in our
composes which sets it to /usr/share/rpm. So then e.g. the `rpm` CLI
doesn't actually need the `/var/lib/rpm` backcompat link anymore, though
there's no harm in leaving it.

In the future, we should be able to drop this once we move all of Fedora
to `/usr/lib/sysimage/rpm` (see
coreos/fedora-coreos-tracker#639).

Closes: #2548
  • Loading branch information
jlebon authored and openshift-merge-robot committed Feb 9, 2021
1 parent 8ab604d commit 99486a7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
19 changes: 19 additions & 0 deletions rust/src/composepost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use std::io;
use std::io::{BufRead, Write};
use std::path::Path;

/* See rpmostree-core.h */
const RPMOSTREE_RPMDB_LOCATION: &'static str = "usr/share/rpm";

// rpm-ostree uses /home → /var/home by default as generated by our
// rootfs; we don't expect people to change this. Let's be nice
// and also fixup the $HOME entries generated by `useradd` so
Expand Down Expand Up @@ -55,6 +58,21 @@ fn postprocess_presets(rootfs_dfd: &openat::Dir) -> Result<()> {
Ok(())
}

// We keep hitting issues with the ostree-remount preset not being
// enabled; let's just do this rather than trying to propagate the
// preset everywhere.
fn postprocess_rpm_macro(rootfs_dfd: &openat::Dir) -> Result<()> {
let rpm_macros_dir = "usr/lib/rpm/macros.d";
rootfs_dfd.ensure_dir_all(rpm_macros_dir, 0o755)?;
let rpm_macros_dfd = rootfs_dfd.sub_dir(rpm_macros_dir)?;
rpm_macros_dfd.write_file_with("macros.rpm-ostree", 0o644, |w| -> Result<()> {
w.write_all(b"%_dbpath /")?;
w.write_all(RPMOSTREE_RPMDB_LOCATION.as_bytes())?;
Ok(())
})?;
Ok(())
}

// This function does two things: (1) make sure there is a /home --> /var/home substitution rule,
// and (2) make sure there *isn't* a /var/home -> /home substition rule. The latter check won't
// technically be needed once downstreams have:
Expand Down Expand Up @@ -90,6 +108,7 @@ pub(crate) fn compose_postprocess_final(rootfs_dfd: i32) -> CxxResult<()> {
postprocess_useradd,
postprocess_presets,
postprocess_subs_dist,
postprocess_rpm_macro,
];
Ok(tasks.par_iter().try_for_each(|f| f(&rootfs_dfd))?)
}
6 changes: 4 additions & 2 deletions src/libpriv/rpmostree-core.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,8 @@ rpmostree_context_setup (RpmOstreeContext *self,
dnf_context_set_rpm_macro (self->dnfctx, "_install_langs", opt->str);
}

/* This is what we use as default. */
/* This is what we use as default. Note we should be able to drop this in the
* future now that we inject a macro to set that value in our OSTrees. */
dnf_context_set_rpm_macro (self->dnfctx, "_dbpath", "/" RPMOSTREE_RPMDB_LOCATION);

/* Set the database backend only in the compose path. It then becomes the default
Expand Down Expand Up @@ -4123,7 +4124,8 @@ rpmostree_context_assemble (RpmOstreeContext *self,
rpmtsSetRootDir (ordering_ts, dnf_context_get_install_root (dnfctx));

/* First for the ordering TS, set the dbpath to relative, which will also gain
* the root dir.
* the root dir. Note we should be able to drop this in the future now that we
* inject a macro to set that value in our OSTrees.
*/
set_rpm_macro_define ("_dbpath", "/" RPMOSTREE_RPMDB_LOCATION);

Expand Down
1 change: 1 addition & 0 deletions src/libpriv/rpmostree-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ G_BEGIN_DECLS
#define RPMOSTREE_DIR_LOCK "lock"

/* See http://lists.rpm.org/pipermail/rpm-maint/2017-October/006681.html */
/* This is also defined on the Rust side. */
#define RPMOSTREE_RPMDB_LOCATION "usr/share/rpm"
#define RPMOSTREE_SYSIMAGE_DIR "usr/lib/sysimage"
#define RPMOSTREE_SYSIMAGE_RPMDB RPMOSTREE_SYSIMAGE_DIR "/rpm"
Expand Down
4 changes: 4 additions & 0 deletions tests/compose/libbasic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ done
ostree --repo=${repo} ls ${treeref} /usr/lib/sysimage/rpm >/dev/null
echo "ok db"

ostree --repo=${repo} cat ${treeref} /usr/lib/rpm/macros.d/macros.rpm-ostree > rpm-ostree-macro.txt
assert_file_has_content_literal rpm-ostree-macro.txt '%_dbpath /usr/share/rpm'
echo "ok rpm macro"

ostree --repo=${repo} show --print-metadata-key exampleos.gitrepo ${treeref} > meta.txt
assert_file_has_content meta.txt 'rev.*97ec21c614689e533d294cdae464df607b526ab9'
assert_file_has_content meta.txt 'src.*https://gitlab.com/exampleos/custom-atomic-host'
Expand Down

0 comments on commit 99486a7

Please sign in to comment.