-
Notifications
You must be signed in to change notification settings - Fork 51
Closed
Labels
type: a-bugThe described behavior is not working as intended.The described behavior is not working as intended.
Milestone
Description
directory/System/Directory/Internal/Posix.hsc
Lines 283 to 284 in b3184ca
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 rathergetpwuid_r
for thread-safety) - if none are set, raise an error
Inspecting other popular standard library language functions, they seem to do exactly that:
- https://doc.rust-lang.org/std/env/fn.home_dir.html
- https://docs.python.org/3/library/os.path.html#os.path.expanduser
The only thing that is debatable about this is how an empty and set $HOME
will be treated.
Metadata
Metadata
Assignees
Labels
type: a-bugThe described behavior is not working as intended.The described behavior is not working as intended.