From 9f5668ed373be6dd17632c9a3bfd79caa58ad423 Mon Sep 17 00:00:00 2001 From: willmcginnis <40506393+willmcginnis@users.noreply.github.com> Date: Mon, 3 Mar 2025 17:02:58 -0800 Subject: [PATCH] Add caching to CLT installation check Improve the should_install_command_line_tools function by: 1. Caching the result to avoid redundant file existence checks on subsequent calls. 2. Using local variable to capture return values for added clarity --- install.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 71ca08bd..1e9eab63 100755 --- a/install.sh +++ b/install.sh @@ -352,18 +352,28 @@ check_run_command_as_root() { } should_install_command_line_tools() { - if [[ -n "${HOMEBREW_ON_LINUX-}" ]] - then + if [[ -n "${SHOULD_INSTALL_CLT-}" ]]; then + return "${SHOULD_INSTALL_CLT}" + fi + + if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then + SHOULD_INSTALL_CLT=1 return 1 fi - if version_gt "${macos_version}" "10.13" - then + local ret + + if version_gt "${macos_version}" "10.13"; then ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] + ret=$? else - ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] || + ! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] || \ ! [[ -e "/usr/include/iconv.h" ]] + ret=$? fi + + SHOULD_INSTALL_CLT=$ret + return "$ret" } get_permission() {