mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-12 21:43:51 -05:00
Prevent removing symlinks bound to different version (#106)
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
# See `pyenv virtualenvs` for a complete list of installed versions.
|
# See `pyenv virtualenvs` for a complete list of installed versions.
|
||||||
#
|
#
|
||||||
set -e
|
set -e
|
||||||
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
# Provide pyenv completions
|
# Provide pyenv completions
|
||||||
if [ "$1" = "--complete" ]; then
|
if [ "$1" = "--complete" ]; then
|
||||||
@@ -54,11 +55,16 @@ COMPAT_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
|
|||||||
|
|
||||||
if [[ "${DEFINITION}" != "${DEFINITION%/envs/*}" ]]; then
|
if [[ "${DEFINITION}" != "${DEFINITION%/envs/*}" ]]; then
|
||||||
PREFIX="${PYENV_ROOT}/versions/${DEFINITION}"
|
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
|
else
|
||||||
if [ -L "${COMPAT_PREFIX}" ]; then
|
if [ -L "${COMPAT_PREFIX}" ]; then
|
||||||
PREFIX="$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)"
|
PREFIX="$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)"
|
||||||
if [[ "${PREFIX}" == "${PREFIX%/envs/*}" ]]; then
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -54,6 +54,23 @@ setup() {
|
|||||||
[ ! -L "${PYENV_ROOT}/versions/venv27" ]
|
[ ! -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" {
|
@test "not delete virtualenv with same name" {
|
||||||
mkdir -p "${PYENV_ROOT}/versions/2.7.10/envs/venv27"
|
mkdir -p "${PYENV_ROOT}/versions/2.7.10/envs/venv27"
|
||||||
mkdir -p "${PYENV_ROOT}/versions/venv27"
|
mkdir -p "${PYENV_ROOT}/versions/venv27"
|
||||||
|
|||||||
Reference in New Issue
Block a user