]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Drop uid/gid from cache manifest
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 23 Jul 2024 20:59:22 +0000 (22:59 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Jul 2024 06:25:04 +0000 (08:25 +0200)
This does not work as we call have_cache() to determine whether
we need to clean the tools tree or not and when running as root to
boot after building an image the UID/GID will differ and the tools
tree will incorrectly be considered out of date.

Let's move the UID/GID check out of have_cache() and into reuse_cache()
instead. reuse_cache() always runs after we've already potentially
unshared the user namespace and become root, so checking the owner of
the cache directory against the current UID should be a valid check
there.

mkosi/__init__.py
mkosi/config.py

index a987a6c6a023c50009bf3829f4418cc3fbc8c2dd..36a9b470cfe5da9b0c2919c4ff3a5ae157dcd877 100644 (file)
@@ -3332,6 +3332,9 @@ 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, context.root,
index 193f957022ed770ab3b638fce9ae31487ba8c1ec..ff21cc11118aeb945fc0ec09427d068622716c31 100644 (file)
@@ -1363,8 +1363,6 @@ class Args:
         j = cls._load_json(s)
         return dataclasses.replace(cls.default(), **j)
 
-CACHE_UID = os.getuid()
-CACHE_GID = os.getgid()
 
 PACKAGE_GLOBS = (
     "*.rpm",
@@ -1657,8 +1655,6 @@ class Config:
 
     def cache_manifest(self) -> dict[str, Any]:
         return {
-            "uid": CACHE_UID,
-            "gid": CACHE_GID,
             "distribution": self.distribution,
             "release": self.release,
             "mirror": self.mirror,