fix(install): clean up stale symlinks and detect manifest spec drift#1
Merged
Conversation
Two related correctness fixes for the bin/man/completions install flow. 1. Reap stale symlinks before re-extracting. installFromAsset wiped the tool's ToolDir and recreated symlinks for everything in the current manifest entry — but never removed the previous install's symlinks first. If the user renamed a bin spec (e.g. bin = ["old"] → bin = ["new"]) or removed a man/ completion entry, the old symlinks in BinDir/ManDir/completion dirs remained, dangling into the now-deleted ToolDir. Fix: call m.removeToolSymlinks(name) at the top of installFromAsset, before os.RemoveAll(toolDir). The reaper only removes symlinks whose targets resolve into the tool's ToolDir, so it's safe to call when no prior install exists. 2. Detect manifest asset-spec drift in isUpToDate. isUpToDate compared only the release tag, so adding a new man/completion entry to an already-installed tool (or renaming a bin) at the same release tag was reported as "up to date" and the new symlinks were never created — the user had to know to pass --force. Fix: also compare state.Bin/Man/Completions against the manifest entry as unordered sets, and return false when any of them differ. Adds a small stringSlicesEqual helper. Both fixes are independent of any particular asset class — they apply equally to bin, man, and completions. Regression tests added for both behaviors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Owner
Author
|
@copilot Review this PR |
The changes look good. Here's my review:
Tests
|
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.
Two related correctness fixes for the bin/man/completions install flow. Both surface pre-existing latent bugs that are independent of any particular asset class.
1. Reap stale symlinks before re-extracting
installFromAssetwiped the tool'sToolDirand recreated symlinks for everything in the current manifest entry — but never removed the previous install's symlinks first. If the user renamed a bin spec (e.g.bin = [\"old\"]→bin = [\"new\"]) or removed aman/completionentry, the old symlinks inBinDir/ManDir/completion dirs remained, dangling into the now-deletedToolDir.Fix: call
m.removeToolSymlinks(name)at the top ofinstallFromAsset, beforeos.RemoveAll(toolDir). The reaper only removes symlinks whose targets resolve into the tool'sToolDir, so it's safe to call when no prior install exists.2. Detect manifest asset-spec drift in
isUpToDateisUpToDatecompared only the release tag, so adding a newman/completionentry to an already-installed tool (or renaming a bin) at the same release tag was reported as "up to date" and the new symlinks were never created — the user had to know to pass `--force`.Fix: also compare `state.Bin/Man/Completions` against the manifest entry as unordered sets, and return false when any of them differ. Adds a small `stringSlicesEqual` helper.
Tests
Two regression tests cover the behaviors:
Full `go vet ./...` and `go test ./...` pass.