Skip to content

Commit f362d10

Browse files
committed
Fixed 'Inappropriate ioctl for device' problem on posix systems
1 parent 6e86f8a commit f362d10

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Diff for: git/util.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
SlidingWindowMapManager,
2121
SlidingWindowMapBuffer
2222
)
23-
23+
# Import the user database on unix based systems
24+
if os.name == "posix":
25+
import pwd
2426

2527

2628
__all__ = ( "stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux",
@@ -144,12 +146,17 @@ def __getslice__(self, start, end):
144146

145147
def get_user_id():
146148
""":return: string identifying the currently active system user as name@node
147-
:note: user can be set with the 'USER' environment variable, usually set on windows"""
148-
ukn = 'UNKNOWN'
149-
username = os.environ.get('USER', os.environ.get('USERNAME', ukn))
150-
if username == ukn and hasattr(os, 'getlogin'):
151-
username = os.getlogin()
152-
# END get username from login
149+
:note: user can be set with the 'USER' environment variable, usually set on windows
150+
:note: on unix based systems you can use the password database
151+
to get the login name of the effective process user"""
152+
if os.name == "posix":
153+
username = pwd.getpwuid(os.geteuid()).pw_name
154+
else:
155+
ukn = 'UNKNOWN'
156+
username = os.environ.get('USER', os.environ.get('USERNAME', ukn))
157+
if username == ukn and hasattr(os, 'getlogin'):
158+
username = os.getlogin()
159+
# END get username from login
153160
return "%s@%s" % (username, platform.node())
154161

155162
def is_git_dir(d):

0 commit comments

Comments
 (0)