Skip to content

Commit

Permalink
Fix abs_dirname for relative symlinks in same directory
Browse files Browse the repository at this point in the history
Ref (abs_dirname in bats): sstephenson/bats#224
Ref: rbenv/rbenv#868

Fixes pyenv#580
  • Loading branch information
blueyed committed Sep 19, 2018
1 parent 5603eb5 commit 4f21d9a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
9 changes: 6 additions & 3 deletions libexec/pyenv
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ else
# Use a subshell to avoid changing the current path
(
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
cd_path="${path%/*}"
if [[ "$cd_path" != "$path" ]]; then
cd "$cd_path"
fi
name="${path##*/}"
path="$(resolve_link "$name" || true)"
done

pwd
echo "$PWD"
)
}
fi
Expand Down
13 changes: 7 additions & 6 deletions plugins/python-build/bin/python-build
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,21 @@ resolve_link() {
}

abs_dirname() {
local cwd="$(pwd)"
local path="$1"

# Use a subshell to avoid modifying the current path
# Use a subshell to avoid changing the current path
(
while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
cd_path="${path%/*}"
if [[ "$cd_path" != "$path" ]]; then
cd "$cd_path"
fi
name="${path##*/}"
path="$(resolve_link "$name" || true)"
done

pwd
echo "$PWD"
)
# cd "$cwd"
}

capitalize() {
Expand Down
9 changes: 9 additions & 0 deletions test/pyenv_ext.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ load test_helper
PYENV_FILE_ARG="${PYENV_TEST_DIR}/dir2/symlink.py" run pyenv echo PYENV_DIR
assert_output "${PYENV_TEST_DIR}/dir1"
}

@test "should handle relative symlinks for file argument (#580)" {
mkdir -p "${PYENV_TEST_DIR}"
cd "${PYENV_TEST_DIR}"
touch file.py
ln -s file.py symlink.py
PYENV_FILE_ARG="symlink.py" run pyenv echo PYENV_DIR
assert_output "${PYENV_TEST_DIR}"
}

0 comments on commit 4f21d9a

Please sign in to comment.