]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
centos: Fix rpmdb location
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 12 Jan 2023 13:47:06 +0000 (14:47 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 12 Jan 2023 13:59:29 +0000 (14:59 +0100)
The previous logic was not working correctly. Let's simplify the
logic by only executing it for centos and only working in one
direction, if the rpmdb is written to /usr/lib/sysimage/rpm, let's
move it back to /var/lib/rpm on CentOS.

mkosi/__init__.py
mkosi/distributions/centos.py

index 3ec1d008acf5b549a6e9cfaeab3b5a62179c4f21..97ba0344435aec21b234f6da32146ea5a7f7631a 100644 (file)
@@ -511,21 +511,6 @@ def remove_files(state: MkosiState) -> None:
         remove_glob(*paths)
 
 
-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():
-        with complete_step("Creating compat symlink /var/lib/rpm → /usr/lib/sysimage/rpm"):
-            # Move content, if any, from the old location to the new one
-            if rpmdb_old.exists():
-                unlink_try_hard(rpmdb)
-                shutil.move(cast(str, rpmdb_old), rpmdb)
-
-            # Create the symlink in exactly the same fashion that Fedora does
-            rpmdb_old.symlink_to("../../usr/lib/sysimage/rpm")
-
-
 def parse_epel_release(release: str) -> int:
     fields = release.split(".")
     if fields[0].endswith("-stream"):
@@ -543,12 +528,6 @@ def install_distribution(state: MkosiState, cached: bool) -> None:
     with mount_cache(state):
         state.installer.install(state)
 
-    # 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(state.root)
-
 
 def remove_packages(state: MkosiState) -> None:
     """Remove packages listed in config.remove_packages"""
index c59a4534a15d685df2882e9e3447518863b6d6ab..7bea5ef2f6d3ccec657a6fe6f246144affffb9c8 100644 (file)
@@ -1,7 +1,8 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
+import shutil
 from pathlib import Path
-from typing import List, Tuple
+from typing import List, Tuple, cast
 
 from mkosi.backend import (
     Distribution,
@@ -15,6 +16,21 @@ from mkosi.backend import (
 )
 from mkosi.distributions import DistributionInstaller
 from mkosi.distributions.fedora import Repo, install_packages_dnf, invoke_dnf, setup_dnf
+from mkosi.remove import unlink_try_hard
+
+
+def move_rpm_db(root: Path) -> None:
+    """Link /var/lib/rpm to /usr/lib/sysimage/rpm for compat with old rpm"""
+    olddb = root / "var/lib/rpm"
+    newdb = root / "usr/lib/sysimage/rpm"
+
+    if newdb.exists():
+        with complete_step("Moving rpm database /usr/lib/sysimage/rpm → /var/lib/rpm"):
+            unlink_try_hard(olddb)
+            shutil.move(cast(str, newdb), olddb)
+
+            if not any(newdb.parent.iterdir()):
+                newdb.parent.rmdir()
 
 
 class CentosInstaller(DistributionInstaller):
@@ -59,6 +75,10 @@ class CentosInstaller(DistributionInstaller):
 
         install_packages_dnf(state, packages)
 
+        # On Fedora, the default rpmdb has moved to /usr/lib/sysimage/rpm so if that's the case we need to
+        # move it back to /var/lib/rpm on CentOS.
+        move_rpm_db(state.root)
+
         # Centos Stream 8 and below can't write to the sqlite db backend used by
         # default in newer RPM releases so let's rebuild the DB to use the old bdb
         # backend instead. Because newer RPM releases have dropped support for the