From: Daan De Meyer Date: Thu, 23 Jan 2025 17:02:28 +0000 (+0100) Subject: Do not check uid in have_cache() for default tools tree X-Git-Tag: v25.1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1f4e67c13928b0f68a6d622e8f30eff659986ae;p=thirdparty%2Fmkosi.git Do not check uid in have_cache() for default tools tree 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. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 59c11a4ab..c05a1c12d 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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(