diff --git a/libexec/pyenv-rehash b/libexec/pyenv-rehash index a4f651c5..2b2b8248 100755 --- a/libexec/pyenv-rehash +++ b/libexec/pyenv-rehash @@ -34,6 +34,11 @@ release_lock() { remove_prototype_shim } +if [ ! -w "$SHIM_PATH" ]; then + echo "pyenv: cannot rehash: $SHIM_PATH isn't writable" + exit 1 +fi + unset acquired for _ in $(seq "${PYENV_REHASH_TIMEOUT:-60}"); do if acquire_lock 2>/dev/null; then @@ -46,11 +51,7 @@ for _ in $(seq "${PYENV_REHASH_TIMEOUT:-60}"); do done if [ -z "${acquired}" ]; then - if [ -w "$SHIM_PATH" ]; then - echo "pyenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" - else - echo "pyenv: cannot rehash: $SHIM_PATH isn't writable" - fi + echo "pyenv: cannot rehash: $PROTOTYPE_SHIM_PATH exists" exit 1 fi diff --git a/test/rehash.bats b/test/rehash.bats index 99612733..c5694f4e 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -25,6 +25,7 @@ create_executable() { } @test "rehash in progress" { + export PYENV_REHASH_TIMEOUT=1 mkdir -p "${PYENV_ROOT}/shims" touch "${PYENV_ROOT}/shims/.pyenv-shim" run pyenv-rehash