From: Daan De Meyer Date: Mon, 24 Apr 2023 10:42:48 +0000 (+0200) Subject: Fix rpmdb symlinks X-Git-Tag: v15~207^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee2920ab3708c735c5a0ceab113aa51e8a063f8b;p=thirdparty%2Fmkosi.git Fix rpmdb symlinks 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(). --- diff --git a/mkosi/distributions/centos.py b/mkosi/distributions/centos.py index 1102532c0..2c784a194 100644 --- a/mkosi/distributions/centos.py +++ b/mkosi/distributions/centos.py @@ -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): diff --git a/mkosi/distributions/fedora.py b/mkosi/distributions/fedora.py index 255b2eed5..2b1543b3d 100644 --- a/mkosi/distributions/fedora.py +++ b/mkosi/distributions/fedora.py @@ -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))