]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Fix rpmdb symlinks
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 24 Apr 2023 10:42:48 +0000 (12:42 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 24 Apr 2023 10:42:48 +0000 (12:42 +0200)
On CentOS, we were creating the wrong symlink. Let's use a proper
relative symlink that always works regardless of whether we're chrooted
or not.

On Debian/Ubuntu, we weren't creating a symlink at all. So let's make
sure we also create a symlink there and use a relative symlink there as
well.

We use os.path.relpath() because Path().relative_to() can only do relative
paths to subpaths which isn't the case here. In the future we can set
strict=False and use relative_to().

mkosi/distributions/centos.py
mkosi/distributions/fedora.py

index 1102532c063fdd038d25ca47acd147690ca9afa5..2c784a19403d444df4643db01d7f01e5aa8ca08b 100644 (file)
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
+import os
 import shutil
 from collections.abc import Sequence
 from pathlib import Path
@@ -21,7 +22,7 @@ def move_rpm_db(root: Path) -> None:
             unlink_try_hard(olddb)
             shutil.move(newdb, olddb)
 
-            newdb.symlink_to(olddb)
+            newdb.symlink_to(os.path.relpath(olddb, start=newdb.parent))
 
 
 class CentosInstaller(DistributionInstaller):
index 255b2eed5f8efced4d4e5f924056449c501f857c..2b1543b3d90c7181496a03a2dcffc017e506943b 100644 (file)
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: LGPL-2.1+
 
 import logging
+import os
 import shutil
 import urllib.parse
 import urllib.request
@@ -172,14 +173,15 @@ def invoke_dnf(state: MkosiState, command: str, packages: Iterable[str], env: Ma
     if distribution not in (Distribution.debian, Distribution.ubuntu):
         return
 
-    # On Debian, rpm/dnf ship with a patch to store the rpmdb under ~/
-    # so it needs to be copied back in the right location, otherwise
-    # the rpmdb will be broken. See: https://bugs.debian.org/1004863
+    # On Debian, rpm/dnf ship with a patch to store the rpmdb under ~/ so it needs to be copied back in the
+    # right location, otherwise the rpmdb will be broken. See: https://bugs.debian.org/1004863. We also
+    # replace it with a symlink so that any further rpm operations immediately use the correct location.
     rpmdb_home = state.root / "root/.rpmdb"
-    if rpmdb_home.exists():
+    if rpmdb_home.exists() and not rpmdb_home.is_symlink():
         # Take into account the new location in F36
         rpmdb = state.root / "usr/lib/sysimage/rpm"
         if not rpmdb.exists():
             rpmdb = state.root / "var/lib/rpm"
         unlink_try_hard(rpmdb)
         shutil.move(rpmdb_home, rpmdb)
+        rpmdb_home.symlink_to(os.path.relpath(rpmdb, start=rpmdb_home.parent))