]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Replace check_uid with a "tools" image check in have_cache()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 28 Jan 2025 19:18:36 +0000 (20:18 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 29 Jan 2025 09:56:25 +0000 (10:56 +0100)
We have access to the config object in have_cache() and this argument
is specifically intended to be used whenever we pass the default tools
tree to have_cache(), so let's just do the check based on config.image
in have_cache() itself.

mkosi/__init__.py

index 694deb357758d608c43609c6bc849b1e2798f75b..d7bfcf30d5151666a9656f0963f99870e160bf96 100644 (file)
@@ -3068,7 +3068,7 @@ def save_cache(context: Context) -> None:
         )
 
 
-def have_cache(config: Config, check_uid: bool = True) -> bool:
+def have_cache(config: Config) -> bool:
     if not config.incremental or config.base_trees or config.overlay:
         return False
 
@@ -3077,7 +3077,7 @@ def have_cache(config: Config, check_uid: bool = True) -> bool:
         logging.debug(f"{final} does not exist, not reusing cached images")
         return False
 
-    if check_uid and (uid := final.stat().st_uid) != os.getuid():
+    if config.image != "tools" and (uid := final.stat().st_uid) != os.getuid():
         logging.debug(
             f"{final} uid ({uid}) does not match user uid ({os.getuid()}), not reusing cached images"
         )
@@ -4794,7 +4794,7 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
         tools
         and (
             not (tools.output_dir_or_cwd() / tools.output).exists()
-            or (tools.incremental and not have_cache(tools, check_uid=False))
+            or (tools.incremental and not have_cache(tools))
         )
         and (args.verb != Verb.build or last.output_format == OutputFormat.none)
         and not args.force
@@ -4808,8 +4808,7 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None:
     # If we're doing an incremental build and the cache is not out of date, don't clean up the
     # tools tree so that we can reuse the previous one.
     if tools and (
-        not tools.incremental
-        or ((args.verb == Verb.build or args.force > 0) and not have_cache(tools, check_uid=False))
+        not tools.incremental or ((args.verb == Verb.build or args.force > 0) and not have_cache(tools))
     ):
         if tools.incremental == Incremental.strict:
             die(