Modulecabal-install-3.12.1.0Haskell2010
Distribution.Client.Win32SelfUpgrade
Support for self-upgrading executables on Windows platforms.
- 2 values
- Packagecabal-install-3.12.1.0
- Exports2
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceWin32SelfUpgrade.hs
Explanation
2 declarationsWindows 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