cabal-install-3.10.1.0: The command-line interface for Cabal and Hackage.
Copyright(c) Duncan Coutts 2008
LicenseBSD-like
Maintainercabal-devel@haskell.org
Stabilityprovisional
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Distribution.Client.Win32SelfUpgrade

Contents

Description

Support for self-upgrading executables on Windows platforms.

Synopsis

Explanation

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