Implement improved "get executable path" query
TODO:
-
test the change on -
linux -
freebsd -
macos -
windows
-
-
add tests to test suite -
update getExecutablePath
documentation -
decide and document getExecutablePath
deprecation strategy/schedule -
bikeshed the name of the new interface
System.Environment.getExecutablePath
has some problems:
-
Some system-specific implementations throw an exception in some scenarios, e.g. when the executable file has been deleted
-
The Linux implementation succeeds but returns an invalid FilePath when the file has been deleted.
-
The fallback implementation returns argv[0] which is not necessarily an absolute path, and is subject to manipulation.
-
The documentation does not explain any of this.
Breaking the getExecutablePath API or changing its behaviour is not an appealing direction. So we will provide a new API.
There are two facets to the problem of querying the executable path:
- Does the platform provide a reliable way to do it? This is statically known.
- If so, is there a valid answer, and what is it? This may vary, even over the runtime of a single process.
Accordingly, the type of the new mechanism is:
Maybe (IO (Maybe FilePath))
This commit implements this mechanism, defining the query action for FreeBSD, Linux, macOS and Windows.
Fixes: #10957 (closed) Fixes: #12377 (closed)