Skip to content

Commit ddb928b

Browse files
jleboncgwalters
authored andcommitted
Add /usr/lib/rpm/macros.d/macros.rpm-ostree to set %_dbpath to /usr/share/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: coreos#2548
1 parent 867ccdf commit ddb928b

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

rust/src/composepost.rs

+19
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use std::io;
1212
use std::io::{BufRead, Write};
1313
use std::path::Path;
1414

15+
/* See rpmostree-core.h */
16+
const RPMOSTREE_RPMDB_LOCATION: &'static str = "usr/share/rpm";
17+
1518
// rpm-ostree uses /home → /var/home by default as generated by our
1619
// rootfs; we don't expect people to change this. Let's be nice
1720
// and also fixup the $HOME entries generated by `useradd` so
@@ -55,6 +58,21 @@ fn postprocess_presets(rootfs_dfd: &openat::Dir) -> Result<()> {
5558
Ok(())
5659
}
5760

61+
// We keep hitting issues with the ostree-remount preset not being
62+
// enabled; let's just do this rather than trying to propagate the
63+
// preset everywhere.
64+
fn postprocess_rpm_macro(rootfs_dfd: &openat::Dir) -> Result<()> {
65+
let rpm_macros_dir = "usr/lib/rpm/macros.d";
66+
rootfs_dfd.ensure_dir_all(rpm_macros_dir, 0o755)?;
67+
let rpm_macros_dfd = rootfs_dfd.sub_dir(rpm_macros_dir)?;
68+
rpm_macros_dfd.write_file_with("macros.rpm-ostree", 0o644, |w| -> Result<()> {
69+
w.write_all(b"%_dbpath /")?;
70+
w.write_all(RPMOSTREE_RPMDB_LOCATION.as_bytes())?;
71+
Ok(())
72+
})?;
73+
Ok(())
74+
}
75+
5876
// This function does two things: (1) make sure there is a /home --> /var/home substitution rule,
5977
// and (2) make sure there *isn't* a /var/home -> /home substition rule. The latter check won't
6078
// technically be needed once downstreams have:
@@ -90,6 +108,7 @@ pub(crate) fn compose_postprocess_final(rootfs_dfd: i32) -> CxxResult<()> {
90108
postprocess_useradd,
91109
postprocess_presets,
92110
postprocess_subs_dist,
111+
postprocess_rpm_macro,
93112
];
94113
Ok(tasks.par_iter().try_for_each(|f| f(&rootfs_dfd))?)
95114
}

src/libpriv/rpmostree-core.cxx

+4-2
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ rpmostree_context_setup (RpmOstreeContext *self,
753753
dnf_context_set_rpm_macro (self->dnfctx, "_install_langs", opt->str);
754754
}
755755

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

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

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

src/libpriv/rpmostree-core.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ G_BEGIN_DECLS
4242
#define RPMOSTREE_DIR_LOCK "lock"
4343

4444
/* See http://lists.rpm.org/pipermail/rpm-maint/2017-October/006681.html */
45+
/* This is also defined on the Rust side. */
4546
#define RPMOSTREE_RPMDB_LOCATION "usr/share/rpm"
4647
#define RPMOSTREE_SYSIMAGE_DIR "usr/lib/sysimage"
4748
#define RPMOSTREE_SYSIMAGE_RPMDB RPMOSTREE_SYSIMAGE_DIR "/rpm"

tests/compose/libbasic-test.sh

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ done
3939
ostree --repo=${repo} ls ${treeref} /usr/lib/sysimage/rpm >/dev/null
4040
echo "ok db"
4141

42+
ostree --repo=${repo} cat ${treeref} /usr/lib/rpm/macros.d/macros.rpm-ostree > rpm-ostree-macro.txt
43+
assert_file_has_content_literal rpm-ostree-macro.txt '%_dbpath /usr/share/rpm'
44+
echo "ok rpm macro"
45+
4246
ostree --repo=${repo} show --print-metadata-key exampleos.gitrepo ${treeref} > meta.txt
4347
assert_file_has_content meta.txt 'rev.*97ec21c614689e533d294cdae464df607b526ab9'
4448
assert_file_has_content meta.txt 'src.*https://gitlab.com/exampleos/custom-atomic-host'

0 commit comments

Comments
 (0)