]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Move uid check back to have_cache()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 21 Jan 2025 22:47:57 +0000 (23:47 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 22 Jan 2025 13:11:18 +0000 (14:11 +0100)
We moved this to reuse_cache() before the introduction of mkosi-sandbox
because we would change uids during execution. Now that we don't do that
anymore, we can move the check back to have_cache().

mkosi/__init__.py

index 10ace4d6cdcb24effdf4bf6f2cd0ed033f40763b..2c072df514b8e11c623eafb45bfaf505c58fbaeb 100644 (file)
@@ -3068,6 +3068,12 @@ 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():
+        logging.debug(
+            f"{final} uid ({uid}) does not match user uid ({os.getuid()}), not reusing cached images"
+        )
+        return False
+
     if need_build_overlay(config) and not build.exists():
         logging.debug(f"{build} does not exist, not reusing cached images")
         return False
@@ -3102,9 +3108,6 @@ def reuse_cache(context: Context) -> bool:
 
     final, build, _ = cache_tree_paths(context.config)
 
-    if final.stat().st_uid != os.getuid():
-        return False
-
     with complete_step("Copying cached trees"):
         copy_tree(
             final,