-
Notifications
You must be signed in to change notification settings - Fork 98
Return user paths relative to effective user's homedir #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Since `os.path.expanduser()` is used to expand the `~` to the home directory, paths which use `~` will always return a path relative to the home directory of the user under which the python process is running. However, if the euid has been changed, this means that these paths will be incorrect, leading to problems when the non-privleged user tries to write to these paths. This commit fixes that issue by attempting to get the username matching the euid, and using that username (e.g. `~user/.cache`) when invoking `os.path.expanduser()`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, some small style issues
appdirs.py
Outdated
@@ -41,6 +46,12 @@ | |||
system = sys.platform | |||
|
|||
|
|||
def _effective_user(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should probably be placed at the bottom of the file, because all the support functions are located there.
appdirs.py
Outdated
path = os.getenv('XDG_CACHE_HOME', os.path.expanduser('~/.cache')) | ||
if appname: | ||
path = os.path.join(path, appname) | ||
user = _effective_user() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
appdirs.py
Outdated
path = os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config")) | ||
if appname: | ||
path = os.path.join(path, appname) | ||
user = _effective_user() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's cleaner to have _effective_user() inside the format just like you did in user_state_dir() and user_log_dir()
appdirs.py
Outdated
@@ -395,7 +426,7 @@ def user_log_dir(appname=None, appauthor=None, version=None, opinion=True): | |||
""" | |||
if system == "darwin": | |||
path = os.path.join( | |||
os.path.expanduser('~/Library/Logs'), | |||
os.path.expanduser('~{0}/Library/Logs'.format(_effective_user())), | |||
appname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put the round bracket on a new line to match what you did in the other functions, or in the other functions don't put the round bracket on a new line.
@Kriskras99 Thanks for the review, I've made the requested changes. |
Looks great. Now it's up to @zoofood. |
Thanks guys, definitely time to get these merged and a new release out. Appreciate all the efforts! |
Since
os.path.expanduser()
is used to expand the~
to the home directory, paths which use~
will always return a path relative to the home directory of the user under which the python process is running. However, if the euid has been changed, this means that these paths will be incorrect, leading to problems when the non-privleged user tries to write to these paths. For example:This PR fixes that issue by attempting to get the username matching the euid, and using that username (e.g.
~user/.cache
) when invokingos.path.expanduser()
. With the fix, the funcs now return the correct paths relative to the effective user's homedir: