]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Introduce have_cache()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 30 Jan 2024 13:24:17 +0000 (14:24 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 31 Jan 2024 13:24:43 +0000 (14:24 +0100)
Let's split of the logic to check whether we have a cached image
from reuse_cache().

mkosi/__init__.py

index 794d6011d4659fe16102725ed3be4edccf53acbd..159d2ecf09c5de90c170913ab177bcb5ca595783 100644 (file)
@@ -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):