Resolve symlink paths before altering .tool-version files.

This commit is contained in:
Trevor Brown 2018-06-16 22:59:37 -04:00
parent c7fb348ffd
commit 631ad8a005
2 changed files with 15 additions and 0 deletions

View File

@ -17,6 +17,11 @@ version_command() {
file="$(pwd)/.tool-versions"
fi
if [ -L "$file" ]; then
# Resolve file path if symlink
file="$(resolve_symlink "$file")"
fi
check_if_plugin_exists "$plugin"
local version
@ -24,6 +29,7 @@ version_command() {
check_if_version_exists "$plugin" "$version"
done
if [ -f "$file" ] && grep "^$plugin " "$file" > /dev/null; then
sed -i.bak -e "s/^$plugin .*$/$plugin ${versions[*]}/" "$file"
rm "$file".bak

View File

@ -354,3 +354,12 @@ find_tool_versions() {
search_path=$(dirname "$search_path")
done
}
resolve_symlink() {
local symlink
symlink="$1"
# This seems to be the only cross-platform way to resolve symlink paths to
# the real file path
ls -l "$symlink" | sed -e "s|.*-> \(.*\)|\1|"
}