Skip to content

Commit

Permalink
Add caching to CLT installation check
Browse files Browse the repository at this point in the history
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
  • Loading branch information
willmcginnis authored Mar 4, 2025
1 parent 8a20a36 commit 9f5668e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 375 in install.sh

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

Prefer putting braces around variable references even when not strictly required.
return "$ret"

Check failure on line 376 in install.sh

View workflow job for this annotation

GitHub Actions / tests (ubuntu-latest)

Prefer putting braces around variable references even when not strictly required.
}

get_permission() {
Expand Down

0 comments on commit 9f5668e

Please sign in to comment.