]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
dnf: drop metadata_expire=never in metadata syncs
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 31 May 2024 12:02:09 +0000 (14:02 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 31 May 2024 13:21:19 +0000 (15:21 +0200)
With this option on, builds that have an existing cache directory will
generally fail. Fedora doesn't keep old packages on mirrors, and metadata
refers to specific package versions, so stale metadata will cause dnf to fail.

This fixes mkosi test image builds in systemd for me.

mkosi/installer/dnf.py

index 848820903d83725ed14ac1513360f66c9d8c06bc..f6338b00b623d11815d388598f5eca55cb556c35 100644 (file)
@@ -93,7 +93,11 @@ class Dnf(PackageManager):
                     f.write("\n")
 
     @classmethod
-    def cmd(cls, context: Context) -> list[PathString]:
+    def cmd(
+            cls,
+            context: Context,
+            cached_metadata: bool = True,
+    ) -> list[PathString]:
         dnf = cls.executable(context.config)
 
         cmdline: list[PathString] = [
@@ -124,7 +128,7 @@ class Dnf(PackageManager):
 
         if context.config.cacheonly == Cacheonly.always:
             cmdline += ["--cacheonly"]
-        else:
+        elif cached_metadata:
             cmdline += ["--setopt=metadata_expire=never"]
             if dnf == "dnf5":
                 cmdline += ["--setopt=cacheonly=metadata"]
@@ -164,6 +168,7 @@ class Dnf(PackageManager):
         *,
         apivfs: bool = False,
         stdout: _FILE = None,
+        cached_metadata: bool = True,
     ) -> CompletedProcess:
         try:
             with finalize_source_mounts(
@@ -171,7 +176,7 @@ class Dnf(PackageManager):
                 ephemeral=os.getuid() == 0 and context.config.build_sources_ephemeral,
             ) as sources:
                 return run(
-                    cls.cmd(context) + [operation,*arguments],
+                    cls.cmd(context, cached_metadata=cached_metadata) + [operation, *arguments],
                     sandbox=(
                         context.sandbox(
                             binary=cls.executable(context.config),
@@ -199,9 +204,9 @@ class Dnf(PackageManager):
             "makecache",
             arguments=[
                 *(["--refresh"] if context.args.force > 1 or context.config.cacheonly == Cacheonly.never else []),
-                *(["--setopt=cacheonly=none"] if cls.executable(context.config) == "dnf5" else []),
                 *options,
             ],
+            cached_metadata=False,
         )
 
     @classmethod