]> arthur.barton.de Git - bup.git/commitdiff
username/userfullname: use struct names
authorRob Browning <rlb@defaultvalue.org>
Sun, 20 Oct 2019 17:46:37 +0000 (12:46 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 1 Dec 2019 18:20:36 +0000 (12:20 -0600)
Use the pwd names, not indexes.  That's clearer and it'll support
upcoming py3 compatibility work.  While we're at it, start making it
clear these are binary (bytes).

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/helpers.py

index 333a491efef1413299a1f926ab2fab78049d705d..d66b5f17dad32a23331876e3ff58ac2477964388 100644 (file)
@@ -442,7 +442,7 @@ def username():
     global _username
     if not _username:
         uid = os.getuid()
-        _username = pwd_from_uid(uid)[0] or 'user%d' % uid
+        _username = pwd_from_uid(uid).pw_name or b'user%d' % uid
     return _username
 
 
@@ -454,9 +454,9 @@ def userfullname():
         uid = os.getuid()
         entry = pwd_from_uid(uid)
         if entry:
-            _userfullname = entry[4].split(',')[0] or entry[0]
+            _userfullname = entry.pw_gecos.split(b',')[0] or entry.pw_name
         if not _userfullname:
-            _userfullname = 'user%d' % uid
+            _userfullname = b'user%d' % uid
     return _userfullname