wpkg self-upgrade


Since version 0.8.0, wpkg can self-upgrade under all operating systems including MS-Windows.

In case you are unaware of the matter, a running executable has its corresponding .exe file (wpkg.exe in this case) locked against writing and deletion. Under a Unix systems, files can always be deleted or overwritten. The operating system knows how to handle this case by keeping the original on disk, and creating a new file. The original will be physically deleted only once all the users of that file are done (closed the file handle.)

The default result is that an executable cannot self-upgrade since an executable cannot overwrite itself!


wpkg.exe solves this problem by copying itself as copy-of-wpkg.exe and then executing the copy to do the actual upgrade.

It also makes use of an internal option: --running-copy. This option tells wpkg that it is a copy and therefore it should not attempt to make a copy to upgrade itself.

Side Effects

The copy is left behind when the upgrade is finished. It will be removed automatically the next time you run wpkg.exe. This is done that way to avoid starting wpkg.exe from the copy just to delete the copy. This being said, once in a while you may see the copy-of-wpkg.exe file in the bin directory.

If wpkg.exe fails starting its copy then the copy is deleted immediately.

Known Bugs

At this time cygwin fails starting the copy properly. The VC++ and mingw versions are able to start as expected.

Syndicate content