From 19e2b9588a3824e007a7689f9a918336768e120f Mon Sep 17 00:00:00 2001 From: Zach Riggle Date: Mon, 13 Nov 2017 15:12:13 -0600 Subject: [PATCH] Fix $PWD changes when executing Python Specifically, this does not play well with PWD=/proc/self/cwd --- libexec/pyenv | 15 +++++++++------ libexec/pyenv-hooks | 6 +++--- libexec/pyenv-versions | 5 +++-- plugins/python-build/bin/python-build | 5 +++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/libexec/pyenv b/libexec/pyenv index 79a20149..a1266c1f 100755 --- a/libexec/pyenv +++ b/libexec/pyenv @@ -36,9 +36,10 @@ else } abs_dirname() { - local cwd="$PWD" local path="$1" + # Use a subshell to avoid changing the current path + ( while [ -n "$path" ]; do cd "${path%/*}" local name="${path##*/}" @@ -46,7 +47,7 @@ else done pwd - cd "$cwd" + ) } fi @@ -72,11 +73,13 @@ fi if [ -z "${PYENV_DIR}" ]; then PYENV_DIR="$PWD" -else - cd "$PYENV_DIR" 2>/dev/null || abort "cannot change working directory to \`$PYENV_DIR'" - PYENV_DIR="$PWD" - cd "$OLDPWD" fi + +if [ ! -d "$PYENV_DIR" ] || [ ! -e "$PYENV_DIR" ]; then + abort "cannot change working directory to \`$PYENV_DIR'" +fi + +PYENV_DIR=$(cd "$PYENV_DIR" && echo "$PWD") export PYENV_DIR diff --git a/libexec/pyenv-hooks b/libexec/pyenv-hooks index a861c9f1..2c1620f3 100755 --- a/libexec/pyenv-hooks +++ b/libexec/pyenv-hooks @@ -37,10 +37,10 @@ resolve_link() { } realpath() { - local cwd="$PWD" local path="$1" local name - + # Use a subshell to avoid changing the current path + ( while [ -n "$path" ]; do name="${path##*/}" [ "$name" = "$path" ] || cd "${path%/*}" @@ -48,7 +48,7 @@ realpath() { done echo "${PWD}/$name" - cd "$cwd" + ) } fi diff --git a/libexec/pyenv-versions b/libexec/pyenv-versions index 87363c7b..019c0e90 100755 --- a/libexec/pyenv-versions +++ b/libexec/pyenv-versions @@ -44,10 +44,11 @@ if ! enable -f "${BASH_SOURCE%/*}"/pyenv-realpath.dylib realpath 2>/dev/null; th } realpath() { - local cwd="$PWD" local path="$1" local name + # Use a subshell to avoid changing the current path + ( while [ -n "$path" ]; do name="${path##*/}" [ "$name" = "$path" ] || cd "${path%/*}" @@ -55,7 +56,7 @@ if ! enable -f "${BASH_SOURCE%/*}"/pyenv-realpath.dylib realpath 2>/dev/null; th done echo "${PWD}/$name" - cd "$cwd" + ) } fi diff --git a/plugins/python-build/bin/python-build b/plugins/python-build/bin/python-build index 3dfb9385..be180d66 100755 --- a/plugins/python-build/bin/python-build +++ b/plugins/python-build/bin/python-build @@ -60,9 +60,10 @@ resolve_link() { } abs_dirname() { - local cwd="$(pwd)" local path="$1" + # Use a subshell to avoid modifying the current path + ( while [ -n "$path" ]; do cd "${path%/*}" local name="${path##*/}" @@ -70,7 +71,7 @@ abs_dirname() { done pwd - cd "$cwd" + ) } capitalize() {