Skip to content

feat: add Windows support to zemo upgrade#13

Merged
hidetzu merged 2 commits into
mainfrom
feat/upgrade-windows
May 6, 2026
Merged

feat: add Windows support to zemo upgrade#13
hidetzu merged 2 commits into
mainfrom
feat/upgrade-windows

Conversation

@hidetzu
Copy link
Copy Markdown
Owner

@hidetzu hidetzu commented May 6, 2026

Closes #11.

Summary

  • assetName() now returns zemo-x86_64-windows.zip on Windows x86_64.
  • New extractZemoBinaryFromZip helper: stages the downloaded .zip to a sibling temp file (because std.zip.Iterator requires a *File.Reader), iterates the central directory, and decompresses the matching entry to memory. Supports store and deflate.
  • replaceBinary branches on builtin.os.tag. On Windows it now:
    1. Writes the new bytes to <install>.new.
    2. MoveFileExW(install, install + ".old", REPLACE_EXISTING) — rename of a running .exe is allowed on NTFS.
    3. MoveFileExW(install + ".new", install, REPLACE_EXISTING) — promote.
    • On failure of step 3, rolls back by renaming .old back to install.
  • cleanupStaleBinary runs at the top of main() and deletes <exe>.old from a previous upgrade (no-op on non-Windows). The currently-running process can't delete its own .old, so cleanup happens on the next launch.
  • doUpgrade resolves install_path before extraction so the zip path can use its parent directory as scratch space for the temp .zip.

Notes

  • MoveFileExW is extern-declared locally — std.os.windows doesn't expose it in 0.16.
  • std.Io.Dir.renameAbsolute was not used for the running-exe rename: it opens the source with GENERIC_WRITE, which conflicts with the loader's FILE_SHARE_READ | FILE_SHARE_DELETE sharing on a running .exe. MoveFileExW only needs DELETE.
  • MOVEFILE_DELAY_UNTIL_REBOOT was not used as a fallback because it writes to HKLM\...\PendingFileRenameOperations which requires admin. Cleanup at next-launch is the primary mechanism.

Test plan

  • zig build test passes on Linux (existing tar.gz tests + new in-memory zip extraction tests using a hand-rolled stored-zip fixture).
  • zig build -Dtarget=x86_64-windows-gnu produces zemo.exe (verified file output: PE32+ executable for MS Windows).
  • Manual smoke test on Windows x86_64: built a VERSION="0.2.9" variant of this branch, replaced the installed 0.3.0 binary on a real Windows host, then ran the full upgrade flow against the existing v0.3.0 GitHub release.
    • zemo upgrade --check reports Newer version available: v0.2.9 -> v0.3.0.
    • zemo upgrade downloads zemo-x86_64-windows.zip, extracts zemo.exe, replaces the running binary.
    • Subsequent zemo --version shows 0.3.0.
    • No leftover <exe>.old after the next zemo invocation (deleted by cleanupStaleBinary on startup).

hidetzu added 2 commits May 6, 2026 18:36
Closes #11.

- assetName: return `zemo-x86_64-windows.zip` on Windows x86_64.
- extractZemoBinaryFromZip: stage the .zip to a sibling temp file
  (std.zip.Iterator needs a File.Reader), iterate the central
  directory, and decompress the matching entry to memory.
- replaceBinary: branch on os.tag. On Windows, write the new bytes
  to `<install>.new`, MoveFileExW the running `<install>` to
  `<install>.old` (rename of an open .exe is allowed on NTFS), then
  promote `.new` to the install path.
- cleanupStaleBinary: on next zemo launch, best-effort delete
  `<exe>.old` left over from the previous upgrade.
- doUpgrade now resolves install_path before extraction so the
  zip path can use its parent directory as scratch space.

`zig build test` passes on Linux and `zig build -Dtarget=x86_64-windows-gnu`
produces `zemo.exe`. Manual smoke test on Windows is still required
before this can be marked done per the issue's acceptance criteria.
Windows is now supported on this branch (closes #11), so the README
no longer needs to flag it as Unix-only.
@hidetzu hidetzu merged commit f77742b into main May 6, 2026
@hidetzu hidetzu deleted the feat/upgrade-windows branch May 6, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add Windows support to zemo upgrade

1 participant