From: Daan De Meyer Date: Mon, 8 Jul 2024 10:45:23 +0000 (+0200) Subject: Make INVOKING_USER.chown() take /tmp and /var/tmp into account X-Git-Tag: v24~50^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33951627da670df2f38eb6aab3dab196d062871d;p=thirdparty%2Fmkosi.git Make INVOKING_USER.chown() take /tmp and /var/tmp into account Let's also chown the directory to be user owned if located in /tmp or /var/tmp. --- diff --git a/mkosi/user.py b/mkosi/user.py index 823af4fc0..89bfaff3a 100644 --- a/mkosi/user.py +++ b/mkosi/user.py @@ -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):