From: Daan De Meyer Date: Tue, 30 Jan 2024 13:24:17 +0000 (+0100) Subject: Introduce have_cache() X-Git-Tag: v21~77^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=febab51e420fed8ba03502d1c310cd73f09d8edd;p=thirdparty%2Fmkosi.git Introduce have_cache() Let's split of the logic to check whether we have a cached image from reuse_cache(). --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 794d6011d..159d2ecf0 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -2565,17 +2565,17 @@ def save_cache(context: Context) -> None: ) -def reuse_cache(context: Context) -> bool: - if not context.config.incremental or context.config.overlay: +def have_cache(config: Config) -> bool: + if not config.incremental or config.overlay: return False - final, build, manifest = cache_tree_paths(context.config) - if not final.exists() or (need_build_overlay(context.config) and not build.exists()): + final, build, manifest = cache_tree_paths(config) + if not final.exists() or (need_build_overlay(config) and not build.exists()): return False if manifest.exists(): prev = json.loads(manifest.read_text()) - if prev != json.loads(json.dumps(context.config.cache_manifest(), cls=JsonEncoder)): + if prev != json.loads(json.dumps(config.cache_manifest(), cls=JsonEncoder)): return False else: return False @@ -2587,6 +2587,15 @@ def reuse_cache(context: Context) -> bool: if p.exists() and p.stat().st_uid != 0: return False + return True + + +def reuse_cache(context: Context) -> bool: + if not have_cache(context.config): + return False + + final, build, _ = cache_tree_paths(context.config) + with complete_step("Copying cached trees"): install_tree(context, final, context.root) if need_build_overlay(context.config):