fix: clean up stale .old binary at startup instead of via detached process#261
Merged
Merged
Conversation
…ocess On Windows, `replaceBinary()` renames the running exe to `.old` because the OS file-locks it. The previous approach spawned a detached `cmd /c ping -n 2 ... & del` process to clean up after exit, but this was unreliable (process may not spawn, `del` may fail silently, timing races), leaving orphaned `.old` files in ~/.archgate/bin/. Replace the detached cleanup with `cleanupStaleBinary()`, called once at CLI startup as a fire-and-forget async `unlink()`. The file is guaranteed to be unlocked by then. The cleanup is platform-agnostic (uses `getArtifactInfo()` to resolve the binary name) so it works on any supported platform, even though only Windows currently creates `.old` files. The sync `unlinkSync` in `replaceBinary()` is kept as defense-in-depth for leftover `.old` files from previous upgrades. Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
Deploying archgate-cli with
|
| Latest commit: |
ac4336e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://357baee7.archgate-cli.pages.dev |
| Branch Preview URL: | https://fix-cleanup-stale-binary-on.archgate-cli.pages.dev |
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.
Summary
cmd /c ping + delcleanup inreplaceBinary()withcleanupStaleBinary(), a fire-and-forget asyncunlink()called at CLI startup.oldfile is guaranteed to be unlocked by the next CLI invocation, making cleanup reliablegetArtifactInfo()), even though only Windows currently creates.oldfilesunlinkSyncinreplaceBinary()as defense-in-depth for leftover.oldfrom previous upgradesFixes: orphaned
archgate.exe.oldpersisting in~/.archgate/bin/after upgrade on Windows.Test plan
bun run validatepasses (lint, typecheck, format, 690 tests, 23/23 ADR rules, build)replaceBinarycreates.oldfile on WindowscleanupStaleBinarydeletes.oldwhen presentcleanupStaleBinaryresolves silently when no.oldfile exists