rpm-ostree/0001-Add-usr-lib-rpm-macros.d-macros.rpm-ostree-to-set-_d.patch
DistroBaker 4e5186faa2 Merged update from upstream sources
This is an automated DistroBaker update from upstream sources.
If you do not know what this is about or would like to opt out,
contact the OSCI team.

Source: https://src.fedoraproject.org/rpms/rpm-ostree.git#e0b1dfbe1225f55f9a1cff49c3da9530bea346c5
2021-02-17 21:35:25 +00:00

133 lines
5.6 KiB
Diff

From 99486a75e8fb96649564c5b79995513dfde355f0 Mon Sep 17 00:00:00 2001
From: Jonathan Lebon <jonathan@jlebon.com>
Date: Mon, 8 Feb 2021 14:59:12 -0500
Subject: [PATCH] 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:
https://github.com/openSUSE/libsolv/commit/04d4d036b275693a23eef75fba634e7cea2f1a6d
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
https://github.com/coreos/fedora-coreos-tracker/issues/639).
Closes: #2548
---
rust/src/composepost.rs | 19 +++++++++++++++++++
src/libpriv/rpmostree-core.cxx | 6 ++++--
src/libpriv/rpmostree-core.h | 1 +
tests/compose/libbasic-test.sh | 4 ++++
4 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/rust/src/composepost.rs b/rust/src/composepost.rs
index c5bb7402..1b1c97f0 100644
--- a/rust/src/composepost.rs
+++ b/rust/src/composepost.rs
@@ -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
@@ -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:
@@ -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))?)
}
diff --git a/src/libpriv/rpmostree-core.cxx b/src/libpriv/rpmostree-core.cxx
index 51ae71a4..506a0b29 100644
--- a/src/libpriv/rpmostree-core.cxx
+++ b/src/libpriv/rpmostree-core.cxx
@@ -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
@@ -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);
diff --git a/src/libpriv/rpmostree-core.h b/src/libpriv/rpmostree-core.h
index fb347622..ce001232 100644
--- a/src/libpriv/rpmostree-core.h
+++ b/src/libpriv/rpmostree-core.h
@@ -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"
diff --git a/tests/compose/libbasic-test.sh b/tests/compose/libbasic-test.sh
index 883ddf8d..07ae0ab5 100644
--- a/tests/compose/libbasic-test.sh
+++ b/tests/compose/libbasic-test.sh
@@ -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'
--
2.29.2