[Hackage] #291: cabal-install cannot re-install itself on windows

Hackage trac at galois.com
Thu Jun 19 08:08:31 EDT 2008


#291: cabal-install cannot re-install itself on windows
---------------------------------+------------------------------------------
  Reporter:  duncan              |        Owner:         
      Type:  defect              |       Status:  new    
  Priority:  normal              |    Milestone:         
 Component:  cabal-install tool  |      Version:  1.2.3.0
  Severity:  normal              |   Resolution:         
  Keywords:                      |   Difficulty:  normal 
Ghcversion:  6.8.2               |     Platform:  Windows
---------------------------------+------------------------------------------
Comment (by duncan):

 See http://www.catch22.net/tuts/selfdel.asp for a menu of cunning
 trickery.

 Apparently one cannot open an .exe file with `FILE_FLAG_DELETE_ON_CLOSE`
 however one can execute an .exe file which is already open with
 `FILE_FLAG_DELETE_ON_CLOSE`. This is the basis of one of the tricks:

 {{{
 [ Current process ]
 1. Create a new file with FILE_FLAG_DELETE_ON_CLOSE.
 2. Copy the current executable's content into the new file.
 3. Create a new process with the duplicate executable:
 4. Pass the current executable's full path and PID in the call to
 CreateFile.
 5. Sleep for a short time to give the new process time to start.
 6. Close the new file.
 7. Exit current process.

 [ Duplicate process ]
 8.  Wait for the process specified on command-line to die.
 9.  Delete file specified on command-line.
 10. Exit duplicate process.
 }}}

 A problem with implementing this one is getting the synchronisation right.
 Waiting for the new process to start requires synchronisation. We could do
 it by waiting for some time and hoping. Doing it properly needs some kind
 of cross-process lock like a mutex or something hacky like using a file as
 a lock.

 Waiting for the old process to die can be done, though not easily. The
 portable `System.Process` lets us wait for a process, but converting a pid
 into a ProcessHandle would be tricky (internally the types are
 incompatible, `type CPid = Word32` vs `type HANDLE = Ptr ()`).

 It might be more appealing to just leave the old file in place and delete
 it next time round.

-- 
Ticket URL: <http://hackage.haskell.org/trac/hackage/ticket/291#comment:3>
Hackage <http://haskell.org/cabal/>
Hackage: Cabal and related projects


More information about the cabal-devel mailing list