feat: add Windows support to zemo upgrade#13
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11.
Summary
assetName()now returnszemo-x86_64-windows.zipon Windows x86_64.extractZemoBinaryFromZiphelper: stages the downloaded.zipto a sibling temp file (becausestd.zip.Iteratorrequires a*File.Reader), iterates the central directory, and decompresses the matching entry to memory. Supportsstoreanddeflate.replaceBinarybranches onbuiltin.os.tag. On Windows it now:<install>.new.MoveFileExW(install, install + ".old", REPLACE_EXISTING)— rename of a running.exeis allowed on NTFS.MoveFileExW(install + ".new", install, REPLACE_EXISTING)— promote..oldback toinstall.cleanupStaleBinaryruns at the top ofmain()and deletes<exe>.oldfrom 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.doUpgraderesolvesinstall_pathbefore extraction so the zip path can use its parent directory as scratch space for the temp.zip.Notes
MoveFileExWisextern-declared locally —std.os.windowsdoesn't expose it in 0.16.std.Io.Dir.renameAbsolutewas not used for the running-exe rename: it opens the source withGENERIC_WRITE, which conflicts with the loader'sFILE_SHARE_READ | FILE_SHARE_DELETEsharing on a running.exe.MoveFileExWonly needsDELETE.MOVEFILE_DELAY_UNTIL_REBOOTwas not used as a fallback because it writes toHKLM\...\PendingFileRenameOperationswhich requires admin. Cleanup at next-launch is the primary mechanism.Test plan
zig build testpasses 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-gnuproduceszemo.exe(verifiedfileoutput:PE32+ executable for MS Windows).VERSION="0.2.9"variant of this branch, replaced the installed0.3.0binary on a real Windows host, then ran the full upgrade flow against the existingv0.3.0GitHub release.zemo upgrade --checkreportsNewer version available: v0.2.9 -> v0.3.0.zemo upgradedownloadszemo-x86_64-windows.zip, extractszemo.exe, replaces the running binary.zemo --versionshows0.3.0.<exe>.oldafter the nextzemoinvocation (deleted bycleanupStaleBinaryon startup).