]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Do not check uid in have_cache() for default tools tree
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 23 Jan 2025 17:02:28 +0000 (18:02 +0100)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 23 Jan 2025 19:11:38 +0000 (20:11 +0100)
If the tools tree has a cache, it's complete, we're not going to
modify it anymore, and it doesn't matter whether the files in it
are owned by root or an unprivileged user, we'll be able to execute
binaries from it regardless, so let's not check the ownership when
we invoke have_cache() on it.

mkosi/__init__.py

index 59c11a4abd120e2360fe2df428dbc7dba5581741..c05a1c12db7eaccc4bf2c2233cd61a872afa85a9 100644 (file)
@@ -3067,7 +3067,7 @@ def save_cache(context: Context) -> None:
         )
 
 
-def have_cache(config: Config) -> bool:
+def have_cache(config: Config, check_uid: bool = True) -> bool:
     if not config.incremental or config.base_trees or config.overlay:
         return False
 
@@ -3076,7 +3076,7 @@ def have_cache(config: Config) -> bool:
         logging.debug(f"{final} does not exist, not reusing cached images")
         return False
 
-    if (uid := final.stat().st_uid) != os.getuid():
+    if check_uid 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"
         )
@@ -4791,7 +4791,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))
+            or (tools.incremental and not have_cache(tools, check_uid=False))
         )
         and (args.verb != Verb.build or last.output_format == OutputFormat.none)
         and not args.force
@@ -4805,7 +4805,8 @@ 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))
+        not tools.incremental
+        or ((args.verb == Verb.build or args.force > 0) and not have_cache(tools, check_uid=False))
     ):
         if tools.incremental == Incremental.strict:
             die(