Browse Source

rehash: detect and remove a stale lockfile (#3450)

fixes stalling for 60s and failing if some past fault
has resulting in a stale lockfile being present

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
master
native-api 1 week ago
committed by GitHub
parent
commit
70f096a95c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 5 deletions
  1. +7
    -5
      libexec/pyenv-rehash
  2. +12
    -0
      test/rehash.bats

+ 7
- 5
libexec/pyenv-rehash View File

@ -2,7 +2,7 @@
# Summary: Rehash pyenv shims (run this after installing executables)
set -e
[ -n "$PYENV_DEBUG" ] && set -x
[[ -n "$PYENV_DEBUG" ]] && set -x
SHIM_PATH="${PYENV_ROOT}/shims"
PROTOTYPE_SHIM_PATH="${SHIM_PATH}/.pyenv-shim"
@ -15,13 +15,15 @@ declare last_acquire_error
acquire_lock() {
# Ensure only one instance of pyenv-rehash is running at a time by
# setting the shell's `noclobber` option and attempting to write to
# the prototype shim file. If the file already exists, print a warning
# to stderr and exit with a non-zero status.
# the prototype shim file.
local ret
set -o noclobber
last_acquire_error="$( { ( echo -n > "$PROTOTYPE_SHIM_PATH"; ) 2>&1 1>&3 3>&1-; } 3>&1)" || ret=1
# Assuming an old lockfile is stale
# Unknown why this happens for some users but this at least unblocks them
last_acquire_error="$( { ( echo -n > "$PROTOTYPE_SHIM_PATH"; ) 2>&1 1>&3 3>&1-; } 3>&1)" \
|| { find "$PROTOTYPE_SHIM_PATH" -mmin +10 -exec rm -f {} \; ; ret=1; }
set +o noclobber
[ -z "${ret}" ]
[[ -z "${ret}" ]]
}
remove_prototype_shim() {

+ 12
- 0
test/rehash.bats View File

@ -38,6 +38,18 @@ pyenv: cannot rehash: couldn't acquire lock ${PYENV_ROOT}/shims/.pyenv-shim for
assert_success
}
@test "stale lockfile is removed" {
mkdir -p "${PYENV_ROOT}/shims"
#GNU and BSD `date` support generating relative dates via different syntax
# but BusyBox `date` used in Bash Docker images doesn't
touch -t 200001010000.00 "${PYENV_ROOT}/shims/.pyenv-shim"
run pyenv-rehash
assert_success ""
assert [ ! -e "${PYENV_ROOT}/shims/.pyenv-shim" ]
}
@test "creates shims" {
create_alt_executable_in_version "2.7" "python"
create_alt_executable_in_version "2.7" "fab"

Loading…
Cancel
Save