haskell / directory

Platform-independent library for basic file system operations
https://hackage.haskell.org/package/directory
Other
58 stars 47 forks source link

getHomeDirectory on POSIX systems is unreliable #102

Closed hasufell closed 4 years ago

hasufell commented 4 years ago

https://github.com/haskell/directory/blob/b3184cabb8c6a90eec7e921d6ca5058d57da3d82/System/Directory/Internal/Posix.hsc#L283-L284

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:

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 commented 4 years ago

This was resolved by https://github.com/haskell/directory/pull/103.