Skip to content

Commit 9f5668e

Browse files
authored
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
1 parent 8a20a36 commit 9f5668e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

install.sh

+15-5
Original file line numberDiff line numberDiff line change
@@ -352,18 +352,28 @@ check_run_command_as_root() {
352352
}
353353

354354
should_install_command_line_tools() {
355-
if [[ -n "${HOMEBREW_ON_LINUX-}" ]]
356-
then
355+
if [[ -n "${SHOULD_INSTALL_CLT-}" ]]; then
356+
return "${SHOULD_INSTALL_CLT}"
357+
fi
358+
359+
if [[ -n "${HOMEBREW_ON_LINUX-}" ]]; then
360+
SHOULD_INSTALL_CLT=1
357361
return 1
358362
fi
359363

360-
if version_gt "${macos_version}" "10.13"
361-
then
364+
local ret
365+
366+
if version_gt "${macos_version}" "10.13"; then
362367
! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]]
368+
ret=$?
363369
else
364-
! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] ||
370+
! [[ -e "/Library/Developer/CommandLineTools/usr/bin/git" ]] || \
365371
! [[ -e "/usr/include/iconv.h" ]]
372+
ret=$?
366373
fi
374+
375+
SHOULD_INSTALL_CLT=$ret
376+
return "$ret"
367377
}
368378

369379
get_permission() {

0 commit comments

Comments
 (0)