From: Joerg Behrmann Date: Tue, 25 Apr 2023 16:53:57 +0000 (+0200) Subject: Ensure that username and uid are consistent X-Git-Tag: v15~195 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2da952b2d13b2db86a3a570c333ae92c2de911b6;p=thirdparty%2Fmkosi.git Ensure that username and uid are consistent While SUDO_UID and SUDO_GID are useful, since sudo allows to run things as different UID and GID, SUDO_USER is less useful, since it can't change the mapping from UID to name in the namespace it's in. Let's cut out the middleman of getpass.getuser, that looks through several more environment variables (LOGNAME, USER, LNAME, USERNAME) before falling back to os.getuid and looking up the corresponding name and do that right away. --- diff --git a/mkosi/util.py b/mkosi/util.py index e674079b6..526cbe953 100644 --- a/mkosi/util.py +++ b/mkosi/util.py @@ -245,9 +245,7 @@ class InvokingUser: @classmethod def name(cls) -> str: - if uid := cls._uid_from_env(): - return pwd.getpwuid(uid).pw_name - return getpass.getuser() + return pwd.getpwuid(cls.uid()).pw_name @classmethod def home(cls) -> Path: