From 7a45c55cdd6d818b99781d10e4341e75661cb50b Mon Sep 17 00:00:00 2001 From: Sabri Ramadan Date: Thu, 11 Dec 2025 10:53:39 +0100 Subject: [PATCH 1/4] Rename PREFIX env var as it is too generic and might be set by other applications * if set, there is potentially catastrophic loss of data due to the "rm -rf" command being executed on it --- bin/pyenv-virtualenv-delete | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/pyenv-virtualenv-delete b/bin/pyenv-virtualenv-delete index 5fe1a462..1a8e4d6d 100755 --- a/bin/pyenv-virtualenv-delete +++ b/bin/pyenv-virtualenv-delete @@ -58,22 +58,22 @@ VERSION_NAME="${DEFINITION##*/}" COMPAT_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" if [[ "${DEFINITION}" != "${DEFINITION%/envs/*}" ]]; then - PREFIX="${PYENV_ROOT}/versions/${DEFINITION}" + PYENV_VE_PREFIX="${PYENV_ROOT}/versions/${DEFINITION}" if [ -L "${COMPAT_PREFIX}" ]; then - if [[ "${PREFIX}" != "$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)" ]]; then + if [[ "${PYENV_VE_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%/*/envs/*}" != "${PYENV_ROOT}/versions" ]]; then + PYENV_VE_PREFIX="$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)" + if [[ "${PYENV_VE_PREFIX%/*/envs/*}" != "${PYENV_ROOT}/versions" ]]; then echo "pyenv-virtualenv: \`${COMPAT_PREFIX}' is a symlink for unknown location." 1>&2 exit 1 fi else if pyenv-virtualenv-prefix "${VERSION_NAME}" 1>/dev/null 2>&1; then - PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" + PYENV_VE_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" unset COMPAT_PREFIX elif [ -z "$FORCE" ]; then echo "pyenv-virtualenv: \`${DEFINITION}' is not a virtualenv." 1>&2 @@ -83,20 +83,20 @@ else fi if [ -z "$FORCE" ]; then - if [ ! -d "$PREFIX" ]; then + if [ ! -d "$PYENV_VE_PREFIX" ]; then echo "pyenv-virtualenv: virtualenv \`$VERSION_NAME' not installed" >&2 exit 1 fi - read -p "pyenv-virtualenv: remove $PREFIX? (y/N) " + read -p "pyenv-virtualenv: remove $PYENV_VE_PREFIX? (y/N) " case "$REPLY" in y* | Y* ) ;; * ) exit 1 ;; esac fi -if [ -d "$PREFIX" ]; then - rm -rf "$PREFIX" +if [ -d "$PYENV_VE_PREFIX" ]; then + rm -rf "$PYENV_VE_PREFIX" if [ -L "$COMPAT_PREFIX" ]; then rm -rf "$COMPAT_PREFIX" fi From b98c882eca38ca166d9c40e87b827ed1ae67b46b Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Thu, 11 Dec 2025 17:30:08 +0300 Subject: [PATCH 2/4] rename, initialize PREFIX --- bin/pyenv-virtualenv-delete | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/bin/pyenv-virtualenv-delete b/bin/pyenv-virtualenv-delete index 1a8e4d6d..1eb69811 100755 --- a/bin/pyenv-virtualenv-delete +++ b/bin/pyenv-virtualenv-delete @@ -55,25 +55,26 @@ case "$DEFINITION" in esac VERSION_NAME="${DEFINITION##*/}" +ENV_PREFIX="" COMPAT_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" if [[ "${DEFINITION}" != "${DEFINITION%/envs/*}" ]]; then - PYENV_VE_PREFIX="${PYENV_ROOT}/versions/${DEFINITION}" + ENV_PREFIX="${PYENV_ROOT}/versions/${DEFINITION}" if [ -L "${COMPAT_PREFIX}" ]; then - if [[ "${PYENV_VE_PREFIX}" != "$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)" ]]; then + if [[ "${ENV_PREFIX}" != "$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)" ]]; then unset COMPAT_PREFIX fi fi else if [ -L "${COMPAT_PREFIX}" ]; then - PYENV_VE_PREFIX="$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)" - if [[ "${PYENV_VE_PREFIX%/*/envs/*}" != "${PYENV_ROOT}/versions" ]]; then + ENV_PREFIX="$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)" + if [[ "${ENV_PREFIX%/*/envs/*}" != "${PYENV_ROOT}/versions" ]]; then echo "pyenv-virtualenv: \`${COMPAT_PREFIX}' is a symlink for unknown location." 1>&2 exit 1 fi else if pyenv-virtualenv-prefix "${VERSION_NAME}" 1>/dev/null 2>&1; then - PYENV_VE_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" + ENV_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" unset COMPAT_PREFIX elif [ -z "$FORCE" ]; then echo "pyenv-virtualenv: \`${DEFINITION}' is not a virtualenv." 1>&2 @@ -83,20 +84,20 @@ else fi if [ -z "$FORCE" ]; then - if [ ! -d "$PYENV_VE_PREFIX" ]; then + if [ ! -d "$ENV_PREFIX" ]; then echo "pyenv-virtualenv: virtualenv \`$VERSION_NAME' not installed" >&2 exit 1 fi - read -p "pyenv-virtualenv: remove $PYENV_VE_PREFIX? (y/N) " + read -p "pyenv-virtualenv: remove $ENV_PREFIX? (y/N) " case "$REPLY" in y* | Y* ) ;; * ) exit 1 ;; esac fi -if [ -d "$PYENV_VE_PREFIX" ]; then - rm -rf "$PYENV_VE_PREFIX" +if [ -d "$ENV_PREFIX" ]; then + rm -rf "$ENV_PREFIX" if [ -L "$COMPAT_PREFIX" ]; then rm -rf "$COMPAT_PREFIX" fi From 5f6b9dfbc3731d4a2ff91947687e4c490869744b Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Sat, 13 Dec 2025 17:41:31 +0300 Subject: [PATCH 3/4] rename, fix not bailing out with -f if venv is detected missing --- bin/pyenv-virtualenv-delete | 38 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/bin/pyenv-virtualenv-delete b/bin/pyenv-virtualenv-delete index 1eb69811..fb71740a 100755 --- a/bin/pyenv-virtualenv-delete +++ b/bin/pyenv-virtualenv-delete @@ -55,27 +55,28 @@ case "$DEFINITION" in esac VERSION_NAME="${DEFINITION##*/}" -ENV_PREFIX="" -COMPAT_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" +# Must initialize because it might be set in the environment +ENV_PREFIX= +ENV_COMPAT_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" if [[ "${DEFINITION}" != "${DEFINITION%/envs/*}" ]]; then ENV_PREFIX="${PYENV_ROOT}/versions/${DEFINITION}" - if [ -L "${COMPAT_PREFIX}" ]; then - if [[ "${ENV_PREFIX}" != "$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)" ]]; then - unset COMPAT_PREFIX + if [ -L "${ENV_COMPAT_PREFIX}" ]; then + if [[ "${ENV_PREFIX}" != "$(resolve_link "${ENV_COMPAT_PREFIX}" 2>/dev/null || true)" ]]; then + unset ENV_COMPAT_PREFIX fi fi else - if [ -L "${COMPAT_PREFIX}" ]; then - ENV_PREFIX="$(resolve_link "${COMPAT_PREFIX}" 2>/dev/null || true)" + if [ -L "${ENV_COMPAT_PREFIX}" ]; then + ENV_PREFIX="$(resolve_link "${ENV_COMPAT_PREFIX}" 2>/dev/null || true)" if [[ "${ENV_PREFIX%/*/envs/*}" != "${PYENV_ROOT}/versions" ]]; then - echo "pyenv-virtualenv: \`${COMPAT_PREFIX}' is a symlink for unknown location." 1>&2 + echo "pyenv-virtualenv: \`${ENV_COMPAT_PREFIX}' is a symlink for unknown location." 1>&2 exit 1 fi else if pyenv-virtualenv-prefix "${VERSION_NAME}" 1>/dev/null 2>&1; then ENV_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" - unset COMPAT_PREFIX + unset ENV_COMPAT_PREFIX elif [ -z "$FORCE" ]; then echo "pyenv-virtualenv: \`${DEFINITION}' is not a virtualenv." 1>&2 exit 1 @@ -83,12 +84,15 @@ else fi fi -if [ -z "$FORCE" ]; then - if [ ! -d "$ENV_PREFIX" ]; then +if [ ! -d "$ENV_PREFIX" ]; then + if [ -z "$FORCE" ]; then echo "pyenv-virtualenv: virtualenv \`$VERSION_NAME' not installed" >&2 exit 1 - fi + else + exit 0 +fi +if [ -z "$FORCE" ]; then read -p "pyenv-virtualenv: remove $ENV_PREFIX? (y/N) " case "$REPLY" in y* | Y* ) ;; @@ -96,10 +100,8 @@ if [ -z "$FORCE" ]; then esac fi -if [ -d "$ENV_PREFIX" ]; then - rm -rf "$ENV_PREFIX" - if [ -L "$COMPAT_PREFIX" ]; then - rm -rf "$COMPAT_PREFIX" - fi - pyenv-rehash +rm -rf "$ENV_PREFIX" +if [ -L "$ENV_COMPAT_PREFIX" ]; then + rm -rf "$ENV_COMPAT_PREFIX" fi +pyenv-rehash From 7cd9e61e4f4ebef210c069c14c1f5e793df66538 Mon Sep 17 00:00:00 2001 From: Ivan Pozdeev Date: Sat, 13 Dec 2025 18:51:17 +0300 Subject: [PATCH 4/4] fix --- bin/pyenv-virtualenv-delete | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/pyenv-virtualenv-delete b/bin/pyenv-virtualenv-delete index fb71740a..934a1214 100755 --- a/bin/pyenv-virtualenv-delete +++ b/bin/pyenv-virtualenv-delete @@ -90,6 +90,7 @@ if [ ! -d "$ENV_PREFIX" ]; then exit 1 else exit 0 + fi fi if [ -z "$FORCE" ]; then