Fix rehash repair of individually corrupted shims - #3540
Open
aprylewu wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
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.
Prerequisite
pyenv rehashfails to repair shims if one of them has been accidentally overwritten with>file#2378.Description
rehashcurrently compares only the first shim against its prototype. If a later shim is overwritten (for example,printf '2\n' > "$(pyenv root)/shims/python"), it remains broken after rehashing.Check each shim on its first registration and replace only those whose contents differ, leaving valid shims untouched. Default shims are repaired before hooks run; subsequent registrations preserve hook customizations, including the built-in sourceable shims. This includes hidden names explicitly registered by rehash hooks and dangling symlinks; unregistered dotfiles are left alone. The comparison uses a bounded Bash builtin read to avoid an external process per file and to avoid reading an accidentally overwritten large file in full. It preserves trailing newlines, rejects embedded NULs, and counts bytes consistently under Bash 3.2 with multibyte paths. The prototype comment now reflects the existing use of copies.
Checking every shim adds work: on this macOS machine, 10 alternating runs with 100 unchanged shims had median times of 55 ms before and 95 ms after; with 1,000 shims, 701 ms before and 1,300 ms after. A comparison using
cmpper shim took about 311 ms for 100 shims.Tests
BATS_FILE_FILTER=rehash.bats make test-unit: 25 passed, 2 skipped.make test-unit: 258 passed, 8 skipped.bash -n libexec/pyenv-rehashandgit diff --check.Tests ran with macOS Bash 3.2.57 and Bats 1.10.0. Skips are the fish and PowerShell integrations because those shells are unavailable. No Python installation or native extension build was performed.
AI assistance: Codex was used to implement and test this change.