Skip to content
  • Fraser Tweedale's avatar
    Implement improved "get executable path" query · 4b4c5e43
    Fraser Tweedale authored and Marge Bot's avatar Marge Bot committed
    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:
    
    1. Does the platform provide a reliable way to do it?  This is
       statically known.
    
    2. 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
    Fixes: #12377
    4b4c5e43
To find the state of this project's repository at the time of any of these versions, check out the tags.