1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-09-29 20:48:27 +02:00

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
This commit is contained in:
Daniel Hahler 2017-06-23 23:49:00 +02:00
parent 03608115df
commit 87ae363144
2 changed files with 24 additions and 14 deletions

View File

@ -6,17 +6,22 @@ resolve_link() {
} }
abs_dirname() { abs_dirname() {
local cwd="$(pwd)"
local path="$1" local path="$1"
local save_cwd="$PWD"
local dir name
while [ -n "$path" ]; do while [[ -n "$path" ]]; do
cd "${path%/*}" dir="${path%/*}"
local name="${path##*/}" if [[ "$dir" != "$path" ]]; then
cd "$dir"
name="${path##*/}"
else
name="$path"
fi
path="$(resolve_link "$name" || true)" path="$(resolve_link "$name" || true)"
done done
echo "$PWD"
pwd cd "$save_cwd"
cd "$cwd"
} }
PREFIX="$1" PREFIX="$1"

View File

@ -31,17 +31,22 @@ resolve_link() {
} }
abs_dirname() { abs_dirname() {
local cwd="$(pwd)"
local path="$1" local path="$1"
local save_cwd="$PWD"
local dir name
while [ -n "$path" ]; do while [[ -n "$path" ]]; do
cd "${path%/*}" dir="${path%/*}"
local name="${path##*/}" if [[ "$dir" != "$path" ]]; then
cd "$dir"
name="${path##*/}"
else
name="$path"
fi
path="$(resolve_link "$name" || true)" path="$(resolve_link "$name" || true)"
done done
echo "$PWD"
pwd cd "$save_cwd"
cd "$cwd"
} }
expand_path() { expand_path() {