HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulecabal-install-3.12.1.0Haskell2010

Distribution.Client.Win32SelfUpgrade

Support for self-upgrading executables on Windows platforms.

  • 2 values

Explanation

2 declarations

Windows inherited a design choice from DOS that while initially innocuous has rather unfortunate consequences. It maintains the invariant that every open file has a corresponding name on disk. One positive consequence of this is that an executable can always find its own executable file. The downside is that a program cannot be deleted or upgraded while it is running without hideous workarounds. This module implements one such hideous workaround.

The basic idea is:

  • Move our own exe file to a new name

  • Copy a new exe file to the previous name

  • Run the new exe file, passing our own PID and new path

  • Wait for the new process to start

  • Close the new exe file

  • Exit old process

Then in the new process:

  • Inform the old process that we've started

  • Wait for the old process to die

  • Delete the old exe file

  • Exit new process