From 2b0543b2e8dc9532a0435909df4d3064f682ad5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Tue, 27 Jun 2023 20:01:51 +0200 Subject: [PATCH] Fix: Avoid calling realpath of parent crystal in wrapper script (#13596) --- bin/crystal | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/bin/crystal b/bin/crystal index 8e42d4e7ed86..3f7ceb1b88f4 100755 --- a/bin/crystal +++ b/bin/crystal @@ -153,11 +153,8 @@ 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 @@ -165,17 +162,18 @@ if [ "$PARENT_CRYSTAL_COMMAND" = "$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 - 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 @@ -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