]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
mkosi: link /var/lib/rpm to /usr/lib/sysimage/rpm for compat with old rpm
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 10 Jun 2022 15:38:08 +0000 (17:38 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 20 Jun 2022 17:00:00 +0000 (19:00 +0200)
This (partially) fixes #993. There are two aspects of compatiblity: rpm changed
the db backend from bdb to sqlite, and the location was changed. This patch
resolves the second issue. It does using the same logic that e.g. Fedora uses
after the move. But it doesn't do anything for the first part. But luckily, rpm
in Rocky/Centos 8 is linked with support for sqlite, so things work.

We need to unlink /var/lib/rpm because something creates it during
installation. I wanted to just create the symlink if there's nothing there,
but that doesn't work.

mkosi/__init__.py

index 6e6143c22b478cc3970e5e10f4d130e28502e0a4..32c862b050d34713e1e76efde517f98a2e312784 100644 (file)
@@ -2129,6 +2129,17 @@ def invoke_dnf(
         shutil.move(cast(str, rpmdb_home), rpmdb)
 
 
+def link_rpm_db(root: Path) -> None:
+    """Link /var/lib/rpm to /usr/lib/sysimage/rpm for compat with old rpm"""
+    rpmdb = root / "usr/lib/sysimage/rpm"
+    rpmdb_old = root / "var/lib/rpm"
+    if rpmdb.exists() and not rpmdb_old.is_symlink():
+        # We create the symlink in exactly the same fashion that Fedora do
+        with complete_step("Creating compat symlink /var/lib/rpm → /usr/lib/sysimage/rpm"):
+            unlink_try_hard(rpmdb_old)
+            rpmdb_old.symlink_to("../../usr/lib/sysimage/rpm")
+
+
 def install_packages_dnf(
     args: MkosiArgs,
     root: Path,
@@ -3277,6 +3288,11 @@ def install_distribution(args: MkosiArgs, root: Path, do_run_build_script: bool,
     with mount_cache(args, root):
         install[args.distribution](args, root, do_run_build_script)
 
+    # Link /var/lib/rpm→/usr/lib/sysimage/rpm for compat with old rpm.
+    # We do this only if the new location is used, which depends on the dnf
+    # version and configuration on the host. Thus we do this reactively, after the
+    # installation has completed.
+    link_rpm_db(root)
 
 def remove_packages(args: MkosiArgs, root: Path) -> None:
     """Remove packages listed in args.remove_packages"""