mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Merge pull request #370 from asdf-vm/resolve-symlinks-fix
Resolve symlinks fix
This commit is contained in:
commit
60ceeb301e
14
lib/utils.sh
14
lib/utils.sh
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user