mirror of
https://github.com/pyenv/pyenv.git
synced 2026-06-06 00:48:13 +09:00
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>
This commit is contained in:
parent
06fd1ce788
commit
70f096a95c
@ -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() {
|
||||
|
||||
@ -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…
x
Reference in New Issue
Block a user