Skip to content

Commit

Permalink
Fix: Avoid calling realpath of parent crystal in wrapper script (crys…
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored and Blacksmoke16 committed Dec 11, 2023
1 parent 41fd7cb commit 2b0543b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions bin/crystal
Original file line number Diff line number Diff line change
Expand Up @@ -153,29 +153,27 @@ if [ -z "${PARENT_CRYSTAL##*/*}" -a "$(realpath "$PARENT_CRYSTAL")" = "$SCRIPT_P
PARENT_CRYSTAL="crystal"
fi

PARENT_CRYSTAL_COMMAND=$(realpath "$(command -v "$PARENT_CRYSTAL" 2> /dev/null)" 2> /dev/null)
PARENT_CRYSTAL_EXISTS=$(test !$?)

# check if the parent crystal command refers to this script
if [ "$PARENT_CRYSTAL_COMMAND" = "$SCRIPT_PATH" ]; then
if [ "$(realpath "$(command -v "$PARENT_CRYSTAL" 2> /dev/null)" 2> /dev/null)" = "$SCRIPT_PATH" ]; then
# remove the path to this script from PATH
NEW_PATH="$(remove_path_item "$(remove_path_item "$PATH" "$SCRIPT_ROOT")" "bin")"
# if the PATH did not change it will lead to an infinite recursion => display error
if [ "$NEW_PATH" = "$PATH" ]; then
__error_msg 'Could not remove the script bin/crystal from the PATH. Remove it by hand or set the CRYSTAL env variable'
exit 1
fi
PARENT_CRYSTAL_COMMAND=$(realpath "$(PATH=$NEW_PATH command -v "$PARENT_CRYSTAL" 2> /dev/null)" 2> /dev/null)
PARENT_CRYSTAL_EXISTS=$(test !$?)
if [ "$PARENT_CRYSTAL_COMMAND" = "$SCRIPT_PATH" ]; then
PARENT_CRYSTAL=$(PATH=$NEW_PATH command -v "$PARENT_CRYSTAL" 2> /dev/null)
if [ "$(realpath "$PARENT_CRYSTAL" 2> /dev/null)" = "$SCRIPT_PATH" ]; then
__error_msg 'Could not remove the script bin/crystal from the PATH. Remove it by hand or set the CRYSTAL env variable'
exit 1
fi
fi

command -v "$PARENT_CRYSTAL" > /dev/null 2> /dev/null
PARENT_CRYSTAL_EXISTS=$(test !$?)
if ($PARENT_CRYSTAL_EXISTS); then
if [ -z "$CRYSTAL_CONFIG_LIBRARY_PATH" ] || [ -z "$CRYSTAL_LIBRARY_PATH" ]; then
CRYSTAL_INSTALLED_LIBRARY_PATH="$($PARENT_CRYSTAL_COMMAND env CRYSTAL_LIBRARY_PATH 2> /dev/null || echo "")"
CRYSTAL_INSTALLED_LIBRARY_PATH="$($PARENT_CRYSTAL env CRYSTAL_LIBRARY_PATH 2> /dev/null || echo "")"
export CRYSTAL_LIBRARY_PATH=${CRYSTAL_LIBRARY_PATH:-$CRYSTAL_INSTALLED_LIBRARY_PATH}
export CRYSTAL_CONFIG_LIBRARY_PATH=${CRYSTAL_CONFIG_LIBRARY_PATH:-$CRYSTAL_INSTALLED_LIBRARY_PATH}
fi
Expand All @@ -193,5 +191,5 @@ elif !($PARENT_CRYSTAL_EXISTS); then
__error_msg 'You need to have a crystal executable in your path! or set CRYSTAL env variable'
exit 1
else
exec "$PARENT_CRYSTAL_COMMAND" "$@"
exec "$PARENT_CRYSTAL" "$@"
fi

0 comments on commit 2b0543b

Please sign in to comment.