From 87ae363144c7ec21fcf50211b0bbe24d4357755d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 23 Jun 2017 23:49:00 +0200 Subject: [PATCH] Fix abs_dirname There are no tests for this unfortunately and it is copied into two places. Ref: https://github.com/rbenv/rbenv/pull/868 --- install.sh | 19 ++++++++++++------- libexec/bats | 19 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/install.sh b/install.sh index 8bbdd16..a676b37 100755 --- a/install.sh +++ b/install.sh @@ -6,17 +6,22 @@ resolve_link() { } abs_dirname() { - local cwd="$(pwd)" local path="$1" + local save_cwd="$PWD" + local dir name - while [ -n "$path" ]; do - cd "${path%/*}" - local name="${path##*/}" + while [[ -n "$path" ]]; do + dir="${path%/*}" + if [[ "$dir" != "$path" ]]; then + cd "$dir" + name="${path##*/}" + else + name="$path" + fi path="$(resolve_link "$name" || true)" done - - pwd - cd "$cwd" + echo "$PWD" + cd "$save_cwd" } PREFIX="$1" diff --git a/libexec/bats b/libexec/bats index 71f392f..4e87e36 100755 --- a/libexec/bats +++ b/libexec/bats @@ -31,17 +31,22 @@ resolve_link() { } abs_dirname() { - local cwd="$(pwd)" local path="$1" + local save_cwd="$PWD" + local dir name - while [ -n "$path" ]; do - cd "${path%/*}" - local name="${path##*/}" + while [[ -n "$path" ]]; do + dir="${path%/*}" + if [[ "$dir" != "$path" ]]; then + cd "$dir" + name="${path##*/}" + else + name="$path" + fi path="$(resolve_link "$name" || true)" done - - pwd - cd "$cwd" + echo "$PWD" + cd "$save_cwd" } expand_path() {