]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't unconditionally sync when PackageCacheDirectory=/var
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 9 Oct 2025 06:50:44 +0000 (08:50 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 10 Oct 2025 18:40:15 +0000 (20:40 +0200)
If PackageCacheDirectory=/var and a cache directory is not configured
(like in mkosi-initrd), then we'd always sync repository metadata,
regardless of the value of CacheOnly=. Let's fix that by disallowing
CacheOnly=metadata|always if a cache directory is not configured and
only syncing if CacheOnly=never|auto, regardless if a cache directory
is configured or not.

Fixes #3946

mkosi/__init__.py

index 3eb22c224bd83ee9b001ce394dc9317fe2dc6320..250ad84b59955e7eccdba7e098f65f91c35c900f 100644 (file)
@@ -2651,6 +2651,13 @@ def check_inputs(config: Config) -> None:
                 hint="Use Profile= to configure the profile ID",
             )
 
+    if (
+        config.cacheonly not in (Cacheonly.never, Cacheonly.auto)
+        and not config.cache_dir
+        and config.package_cache_dir_or_default() != Path("/var")
+    ):
+        die(f"A cache directory must be configured in order to use CacheOnly={config.cacheonly}")
+
 
 def check_tool(config: Config, *tools: PathString, reason: str, hint: Optional[str] = None) -> Path:
     tool = config.find_binary(*tools)
@@ -4690,10 +4697,8 @@ def sync_repository_metadata(
     (last.package_cache_dir_or_default() / "cache" / subdir).mkdir(parents=True, exist_ok=True)
 
     # Sync repository metadata unless explicitly disabled.
-    if (
-        not last.cache_dir
-        or last.cacheonly == Cacheonly.never
-        or (last.cacheonly == Cacheonly.auto and not any(have_cache(config) for config in images))
+    if last.cacheonly == Cacheonly.never or (
+        last.cacheonly == Cacheonly.auto and not any(have_cache(config) for config in images)
     ):
         with setup_workspace(args, last) as workspace:
             context = Context(