Skip to content
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

getHomeDirectory on POSIX systems is unreliable #102

Closed
hasufell opened this issue Jan 4, 2020 · 1 comment
Closed

getHomeDirectory on POSIX systems is unreliable #102

hasufell opened this issue Jan 4, 2020 · 1 comment
Assignees
Labels
type: a-bug The described behavior is not working as intended.
Milestone

Comments

@hasufell
Copy link
Member

hasufell commented Jan 4, 2020

getHomeDirectoryInternal :: IO FilePath
getHomeDirectoryInternal = getEnv "HOME"

strikes me as a naive implementation. POSIX doesn't say that $HOME is mandatory to be set. The wording is:

If the variables in the following two sections are present in the environment during the execution of an application or utility, they shall be given the meaning described below.

Even worse, getHomeDirectory will error when this optional environment variable is not set.

A better way of doing this would be:

  • if $HOME is set in the environment, return it
  • if $HOME is not set in the environment, look up getpwuid(getuid())->pw_dir, see getpwuid (or rather getpwuid_r for thread-safety)
  • if none are set, raise an error

Inspecting other popular standard library language functions, they seem to do exactly that:

The only thing that is debatable about this is how an empty and set $HOME will be treated.

@Rufflewind Rufflewind added the type: a-bug The described behavior is not working as intended. label Jan 5, 2020
@Rufflewind Rufflewind added this to the 1.3.6.0 milestone Jan 5, 2020
Rufflewind added a commit to Rufflewind/directory that referenced this issue Jan 9, 2020
@Rufflewind
Copy link
Member

This was resolved by #103.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: a-bug The described behavior is not working as intended.
Projects
None yet
Development

No branches or pull requests

2 participants