Merge pull request #370 from asdf-vm/resolve-symlinks-fix

Resolve symlinks fix
This commit is contained in:
Trevor Brown 2018-10-07 21:56:53 -04:00 committed by GitHub
commit 60ceeb301e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 1 deletions

View File

@ -378,5 +378,17 @@ resolve_symlink() {
# This seems to be the only cross-platform way to resolve symlink paths to
# the real file path.
# shellcheck disable=SC2012
ls -l "$symlink" | sed -e 's|.*-> \(.*\)|\1|'
resolved_path=$(ls -l "$symlink" | sed -e 's|.*-> \(.*\)|\1|')
# Check if resolved path is relative or not by looking at the first character.
# If it is a slash we can assume it's root and absolute. Otherwise we treat it
# as relative
case $resolved_path in
/*)
echo "$resolved_path"
;;
*)
echo "$PWD/$resolved_path"
;;
esac
}

View File

@ -268,3 +268,25 @@ teardown() {
[ "$status" -eq 0 ]
[ "$output" = "$PROJECT_DIR/.tool-versions" ]
}
@test "resolve_symlink converts the symlink path to the real file path" {
touch foo
ln -s $(pwd)/foo bar
run resolve_symlink bar
[ "$status" -eq 0 ]
echo $status
[ "$output" = $(pwd)/foo ]
rm -f foo bar
}
@test "resolve_symlink converts relative symlink path to the real file path" {
touch foo
ln -s foo bar
run resolve_symlink bar
[ "$status" -eq 0 ]
echo $status
[ "$output" = $(pwd)/foo ]
rm -f foo bar
}