From 611c8b46c84095833feae9d5aa0ef0a656b032ca Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 9 Oct 2025 08:50:44 +0200 Subject: [PATCH] Don't unconditionally sync when PackageCacheDirectory=/var 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 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 3eb22c224..250ad84b5 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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( -- 2.47.3