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"):
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"""
# 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,
)
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):
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