Browse Source

Fix `realpath` fallback in `rbenv hooks`

The symlinks weren't correctly resolved if they were pointing to a
single path component, such as `ln -s foo bar`.
pull/487/head^2
Mislav Marohnić 9 years ago
parent
commit
7026e529c7
2 changed files with 12 additions and 5 deletions
  1. +5
    -4
      libexec/rbenv-hooks
  2. +7
    -1
      test/hooks.bats

+ 5
- 4
libexec/rbenv-hooks View File

@ -35,16 +35,17 @@ resolve_link() {
} }
realpath() { realpath() {
local cwd="$(pwd)"
local cwd="$PWD"
local path="$1" local path="$1"
local name
while [ -n "$path" ]; do while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
name="${path##*/}"
[ "$name" = "$path" ] || cd "${path%/*}"
path="$(resolve_link "$name" || true)" path="$(resolve_link "$name" || true)"
done done
echo "$(pwd)/$name"
echo "${PWD}/$name"
cd "$cwd" cd "$cwd"
} }
fi fi

+ 7
- 1
test/hooks.bats View File

@ -59,7 +59,13 @@ OUT
mkdir -p "$HOME" mkdir -p "$HOME"
touch "${HOME}/hola.bash" touch "${HOME}/hola.bash"
ln -s "../../home/hola.bash" "${path}/exec/hello.bash" ln -s "../../home/hola.bash" "${path}/exec/hello.bash"
touch "${path}/exec/bright.sh"
ln -s "bright.sh" "${path}/exec/world.bash"
RBENV_HOOK_PATH="$path" run rbenv-hooks exec RBENV_HOOK_PATH="$path" run rbenv-hooks exec
assert_success "${HOME}/hola.bash"
assert_success
assert_output <<OUT
${HOME}/hola.bash
${RBENV_TEST_DIR}/rbenv.d/exec/bright.sh
OUT
} }

Loading…
Cancel
Save