]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Make INVOKING_USER.chown() take /tmp and /var/tmp into account
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Jul 2024 10:45:23 +0000 (12:45 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 8 Jul 2024 10:48:43 +0000 (12:48 +0200)
Let's also chown the directory to be user owned if located in /tmp
or /var/tmp.

mkosi/user.py

index 823af4fc011f916a39af36d6fbfd8f3a36ec7ebd..89bfaff3aa20f793fa183af9b500b7902c3dc497 100644 (file)
@@ -89,10 +89,11 @@ class INVOKING_USER:
     def chown(cls, path: Path) -> None:
         # If we created a file/directory in a parent directory owned by the invoking user, make sure the path and any
         # parent directories are owned by the invoking user as well.
-        if (
-            cls.is_regular_user() and
-            (q := next((parent for parent in path.parents if parent.stat().st_uid == cls.uid), None))
-        ):
+
+        def is_valid_dir(path: Path) -> bool:
+            return path.stat().st_uid == cls.uid or path in (Path("/tmp"), Path("/var/tmp"))
+
+        if cls.is_regular_user() and (q := next((parent for parent in path.parents if is_valid_dir(parent)), None)):
             os.chown(path, INVOKING_USER.uid, INVOKING_USER.gid)
 
             for parent in parents_below(path, q):