Browse Source

Prevent removing symlinks bound to different version (#106)

pull/119/head
Yamashita, Yuu 9 years ago
parent
commit
bb623bd8bf
2 changed files with 24 additions and 1 deletions
  1. +7
    -1
      bin/pyenv-virtualenv-delete
  2. +17
    -0
      test/delete.bats

+ 7
- 1
bin/pyenv-virtualenv-delete View File

@ -11,6 +11,7 @@
# See `pyenv virtualenvs` for a complete list of installed versions.
#
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
@ -54,11 +55,16 @@ COMPAT_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
if [[ "${DEFINITION}" != "${DEFINITION%/envs/*}" ]]; then
PREFIX="${PYENV_ROOT}/versions/${DEFINITION}"
if [ -L "${COMPAT_PREFIX}" ]; then
if [[ "${PREFIX}" != "$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)" ]]; then
unset COMPAT_PREFIX
fi
fi
else
if [ -L "${COMPAT_PREFIX}" ]; then
PREFIX="$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)"
if [[ "${PREFIX}" == "${PREFIX%/envs/*}" ]]; then
echo "pyenv-virtualenv: \`${PREFIX}' is a symlink for unknown location." 1>&2
echo "pyenv-virtualenv: \`${COMPAT_PREFIX}' is a symlink for unknown location." 1>&2
exit 1
fi
else

+ 17
- 0
test/delete.bats View File

@ -54,6 +54,23 @@ setup() {
[ ! -L "${PYENV_ROOT}/versions/venv27" ]
}
@test "not delete virtualenv with different symlink" {
mkdir -p "${PYENV_ROOT}/versions/2.7.8/envs/venv27"
mkdir -p "${PYENV_ROOT}/versions/2.7.10/envs/venv27"
ln -fs "${PYENV_ROOT}/versions/2.7.8/envs/venv27" "${PYENV_ROOT}/versions/venv27"
stub pyenv-rehash "true"
run pyenv-virtualenv-delete -f "2.7.10/envs/venv27"
assert_success
unstub pyenv-rehash
[ ! -d "${PYENV_ROOT}/versions/2.7.10/envs/venv27" ]
[ -L "${PYENV_ROOT}/versions/venv27" ]
}
@test "not delete virtualenv with same name" {
mkdir -p "${PYENV_ROOT}/versions/2.7.10/envs/venv27"
mkdir -p "${PYENV_ROOT}/versions/venv27"

Loading…
Cancel
Save