From: Daan De Meyer Date: Thu, 12 Jan 2023 13:47:06 +0000 (+0100) Subject: centos: Fix rpmdb location X-Git-Tag: v15~367^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f192b9f45a11579ea708776770acb8e4bf7bea3;p=thirdparty%2Fmkosi.git centos: Fix rpmdb location 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. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 3ec1d008a..97ba03444 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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""" diff --git a/mkosi/distributions/centos.py b/mkosi/distributions/centos.py index c59a4534a..7bea5ef2f 100644 --- a/mkosi/distributions/centos.py +++ b/mkosi/distributions/centos.py @@ -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