mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Merge pull request #1216 from blueyed/abs_dirname
Fix abs_dirname for relative symlinks in same directory
This commit is contained in:
commit
3faeda67bb
3 changed files with 22 additions and 9 deletions
|
@ -41,12 +41,15 @@ else
|
||||||
# Use a subshell to avoid changing the current path
|
# Use a subshell to avoid changing the current path
|
||||||
(
|
(
|
||||||
while [ -n "$path" ]; do
|
while [ -n "$path" ]; do
|
||||||
cd "${path%/*}"
|
cd_path="${path%/*}"
|
||||||
local name="${path##*/}"
|
if [[ "$cd_path" != "$path" ]]; then
|
||||||
|
cd "$cd_path"
|
||||||
|
fi
|
||||||
|
name="${path##*/}"
|
||||||
path="$(resolve_link "$name" || true)"
|
path="$(resolve_link "$name" || true)"
|
||||||
done
|
done
|
||||||
|
|
||||||
pwd
|
echo "$PWD"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -60,20 +60,21 @@ resolve_link() {
|
||||||
}
|
}
|
||||||
|
|
||||||
abs_dirname() {
|
abs_dirname() {
|
||||||
local cwd="$(pwd)"
|
|
||||||
local path="$1"
|
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
|
while [ -n "$path" ]; do
|
||||||
cd "${path%/*}"
|
cd_path="${path%/*}"
|
||||||
local name="${path##*/}"
|
if [[ "$cd_path" != "$path" ]]; then
|
||||||
|
cd "$cd_path"
|
||||||
|
fi
|
||||||
|
name="${path##*/}"
|
||||||
path="$(resolve_link "$name" || true)"
|
path="$(resolve_link "$name" || true)"
|
||||||
done
|
done
|
||||||
|
|
||||||
pwd
|
echo "$PWD"
|
||||||
)
|
)
|
||||||
# cd "$cwd"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
capitalize() {
|
capitalize() {
|
||||||
|
|
|
@ -28,3 +28,12 @@ load test_helper
|
||||||
PYENV_FILE_ARG="${PYENV_TEST_DIR}/dir2/symlink.py" run pyenv echo PYENV_DIR
|
PYENV_FILE_ARG="${PYENV_TEST_DIR}/dir2/symlink.py" run pyenv echo PYENV_DIR
|
||||||
assert_output "${PYENV_TEST_DIR}/dir1"
|
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}"
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue