]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Add Cacheonly.never and rename Cacheonly.none to Cacheonly.auto
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 13 Apr 2024 16:03:41 +0000 (18:03 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 14 Apr 2024 13:47:28 +0000 (15:47 +0200)
When set to "never", we'll always sync repository metadata.

mkosi/__init__.py
mkosi/config.py
mkosi/resources/mkosi.md

index 45c347add185a701b35f30e395aaf00edb368783..60c32c6b40090935c818477665c4a94d4314c170 100644 (file)
@@ -324,8 +324,8 @@ def configure_autologin(context: Context) -> None:
 
 
 @contextlib.contextmanager
-def mount_cache_overlay(context: Context) -> Iterator[None]:
-    if not context.config.incremental or not context.config.base_trees or context.config.overlay:
+def mount_cache_overlay(context: Context, cached: bool) -> Iterator[None]:
+    if not context.config.incremental or not context.config.base_trees or context.config.overlay or cached:
         yield
         return
 
@@ -3506,15 +3506,16 @@ def lock_repository_metadata(config: Config) -> Iterator[None]:
 
 
 def copy_repository_metadata(context: Context) -> None:
-    if have_cache(context.config):
-        return
-
     subdir = context.config.distribution.package_manager(context.config).subdir(context.config)
 
-    # Don't copy anything if the repository metadata directories are already populated.
+    # Don't copy anything if the repository metadata directories are already populated and we're not explicitly asked
+    # to sync repository metadata.
     if (
-        any((context.package_cache_dir / "cache" / subdir).glob("*")) or
-        any((context.package_cache_dir / "lib" / subdir).glob("*"))
+        context.config.cacheonly != Cacheonly.never and
+        (
+            any((context.package_cache_dir / "cache" / subdir).glob("*")) or
+            any((context.package_cache_dir / "lib" / subdir).glob("*"))
+        )
     ):
         logging.debug(f"Found repository metadata in {context.package_cache_dir}, not copying repository metadata")
         return
@@ -3562,15 +3563,14 @@ def build_image(context: Context) -> None:
         install_base_trees(context)
         cached = reuse_cache(context)
 
-        if not cached:
-            with mount_cache_overlay(context):
-                copy_repository_metadata(context)
+        with mount_cache_overlay(context, cached):
+            copy_repository_metadata(context)
 
         context.config.distribution.setup(context)
         install_package_directories(context)
 
         if not cached:
-            with mount_cache_overlay(context):
+            with mount_cache_overlay(context, cached):
                 install_skeleton_trees(context)
                 install_distribution(context)
                 run_prepare_scripts(context, build=False)
@@ -4268,7 +4268,10 @@ def rchown_package_manager_dirs(config: Config) -> Iterator[None]:
 
 
 def sync_repository_metadata(context: Context) -> None:
-    if have_cache(context.config) or context.config.cacheonly != Cacheonly.none:
+    if (
+        context.config.cacheonly != Cacheonly.never and
+        (have_cache(context.config) or context.config.cacheonly != Cacheonly.auto)
+    ):
         return
 
     with (
index 7dadb46100bf2c163c3489683aa3dd145a9a031a..b3324e4c59370e5477b309f8d0233e3927870db7 100644 (file)
@@ -259,9 +259,11 @@ class ShimBootloader(StrEnum):
 
 
 class Cacheonly(StrEnum):
-    always = enum.auto()
-    none = enum.auto()
+    always   = enum.auto()
+    auto     = enum.auto()
+    none     = auto
     metadata = enum.auto()
+    never    = enum.auto()
 
 
 class QemuFirmware(StrEnum):
@@ -1898,11 +1900,11 @@ SETTINGS = (
         dest="cacheonly",
         long="--cache-only",
         name="CacheOnly",
-        metavar="CACHEONLY",
         section="Distribution",
-        parse=config_make_enum_parser_with_boolean(Cacheonly, yes=Cacheonly.always, no=Cacheonly.none),
-        default=Cacheonly.none,
+        parse=config_make_enum_parser_with_boolean(Cacheonly, yes=Cacheonly.always, no=Cacheonly.auto),
+        default=Cacheonly.auto,
         help="Only use the package cache when installing packages",
+        choices=Cacheonly.values(),
     ),
     ConfigSetting(
         dest="package_manager_trees",
index fad19033aac08f903c3e41426f41cefcee1f1e40..819680da967f4b59060874bcc1202b2ddf6ecdcf 100644 (file)
@@ -643,13 +643,16 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
 
 `CacheOnly=`, `--cache-only=`
 
-: Takes one of `none`, `metadata` or `always`. If `always`, the package
-  manager is instructed not to contact the network. This provides a
-  minimal level of reproducibility, as long as the package cache is
-  already fully populated. If set to `metadata`, the package manager can
-  still download packages, but we won't sync the repository metadata. If
-  set to `none`, the repository metadata is synced and packages can be
-  downloaded during the build.
+: Takes one of `auto`, `metadata`, `always` or `never`. Defaults to
+  `auto`. If `always`, the package manager is instructed not to contact
+  the network. This provides a minimal level of reproducibility, as long
+  as the package cache is already fully populated. If set to `metadata`,
+  the package manager can still download packages, but we won't sync the
+  repository metadata. If set to `auto`, the repository metadata is
+  synced unless we have a cached image (see `Incremental=`) and packages
+  can be downloaded during the build. If set to `never`, repository
+  metadata is always synced and and packages can be downloaded during
+  the build.
 
 `PackageManagerTrees=`, `--package-manager-tree=`