Fix resolution of relative symlinks

Fixes #366, #625
This commit is contained in:
Trevor Brown 2020-10-08 09:59:50 -04:00
parent 2bf076f3d3
commit 34593c1766
3 changed files with 20 additions and 9 deletions

View File

@ -454,7 +454,10 @@ resolve_symlink() {
printf "%s\\n" "$resolved_path"
;;
*)
printf "%s\\n" "$PWD/$resolved_path"
(
cd "$(dirname "$symlink")" || exit 1
printf "%s\\n" "$PWD/$resolved_path"
)
;;
esac
}

View File

@ -355,18 +355,26 @@ teardown() {
run resolve_symlink bar
[ "$status" -eq 0 ]
echo $status
[ "$output" = $(pwd)/foo ]
rm -f foo bar
}
@test "resolve_symlink converts relative symlink directory path to the real file path" {
mkdir baz
ln -s ../foo baz/bar
run resolve_symlink baz/bar
[ "$status" -eq 0 ]
[ "$output" = $(pwd)/baz/../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
}

View File

@ -208,26 +208,26 @@ teardown() {
}
@test "global should preserve symlinks when setting versions" {
mkdir other-dir
touch other-dir/.tool-versions
mkdir $HOME/other-dir
touch $HOME/other-dir/.tool-versions
ln -s other-dir/.tool-versions $HOME/.tool-versions
run asdf global "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ -L $HOME/.tool-versions ]
[ "$(cat other-dir/.tool-versions)" = "dummy 1.1.0" ]
[ "$(cat $HOME/other-dir/.tool-versions)" = "dummy 1.1.0" ]
}
@test "global should preserve symlinks when updating versions" {
mkdir other-dir
touch other-dir/.tool-versions
mkdir $HOME/other-dir
touch $HOME/other-dir/.tool-versions
ln -s other-dir/.tool-versions $HOME/.tool-versions
run asdf global "dummy" "1.1.0"
run asdf global "dummy" "1.1.0"
[ "$status" -eq 0 ]
[ -L $HOME/.tool-versions ]
[ "$(cat other-dir/.tool-versions)" = "dummy 1.1.0" ]
[ "$(cat $HOME/other-dir/.tool-versions)" = "dummy 1.1.0" ]
}
@test "shell wrapper function should export ENV var" {