haskell / directory

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

`findExecutable "ghc-9.10.1" behaves surprisingly on windows #188

Open hasufell opened 4 weeks ago

hasufell commented 4 weeks ago
ghci> findExecutable "ghc-9.10.1"
Nothing
ghci> findExecutable "ghc-9.10.1.exe"
Just "C:\\ghcup\\bin\\ghc-9.10.1.exe"

This is because "ghc-9.10.1" is considered to contain a file extension. The documentation on SearchPathW states under lpExtension:

The extension to be added to the file name when searching for the file. The first character of the file name extension must be a period (.). The extension is added only if the specified file name does not end with an extension.

hasufell commented 4 weeks ago

So I think, the way we need is this:

searchPathEnvForExes :: OsString -> IO (Maybe OsPath)
searchPathEnvForExes (OsString binary) =
  let binary' = if takeExtension binary == exeExtension then binary else binary <.> exeExtension
  in fmap OsString <$> Win32.searchPath Nothing binary' Nothing

ignoring the lpExtension parameter.

But that would not allow us to search for e.g. foo.bat or other executable-like formats.