From 39b298aa38f47f71d51ad7ffc1ff4c6b62196ccc Mon Sep 17 00:00:00 2001 From: Jakub Kadlcik Date: Sun, 6 Aug 2023 14:07:20 +0200 Subject: [PATCH] Don't use --cacheonly on DNF5 Fix #466 See #363 Actually, it still doesn't work completely but this particular issue is fixed. I am now getting: Auto-installing packages: sudo dnf install -y /tmp/tito/noarch/tito-0.6.24-1.git.0.2a15b8c.fc39.noarch.rpm ... Failed to resolve the transaction: Problem: problem with installed package - cannot install both tito-0.6.24-1.git.0.2a15b8c.fc39.noarch and tito-0.6.24-2.fc39.noarch - conflicting requests Which seems to be fixed in the dnf5 main branch: https://github.com/rpm-software-management/dnf5/issues/722 --- src/tito/builder/main.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/tito/builder/main.py b/src/tito/builder/main.py index 1033fa5..99b0b9d 100644 --- a/src/tito/builder/main.py +++ b/src/tito/builder/main.py @@ -344,7 +344,7 @@ class BuilderBase(object): print reinstall = self.package_manager.is_installed(self.project_name, self.build_version) - cmd = self.package_manager.install(do_install, reinstall=reinstall, auto=True, offline=True, + cmd = self.package_manager.install(do_install, reinstall=reinstall, auto=True, escalate=self.escalate_privileges) print("%s" % cmd) try: @@ -1446,10 +1446,10 @@ class Rpm(object): class Dnf(Rpm): - def install(self, packages, reinstall=False, auto=False, offline=False, escalate=True, **kwargs): + def install(self, packages, reinstall=False, auto=False, escalate=True, **kwargs): action = "reinstall" if reinstall else "install" args = list(filter(lambda x: x, [ - "-C" if offline else None, + "-C" if self.cacheonly else None, "-y" if auto else None, ])) escalation_cmd = "sudo" if escalate else "" @@ -1459,6 +1459,24 @@ class Dnf(Rpm): def builddep(self, spec): return "dnf builddep %s" % spec + @property + def cacheonly(self): + """ + Should a DNF command be as -C/--cacheonly? + """ + # AFAIK metadata refreshing is one of the areas where DNF5 brings the most performance + # improvements. It will help us fix #466 but also a long-time annoying #363. + if self.dnf_version == 5: + return False + return True + + @property + def dnf_version(self): + """ + What DNF version is used? + """ + return 5 if os.readlink("/usr/bin/dnf") == "dnf5" else 4 + class Yum(Rpm): def install(self, packages, **kwargs):