fix: prevent brew bundle hanging on large cask installs

HOMEBREW_NO_QUARANTINE=1 — skips the post-install xattr quarantine walk
  that Gatekeeper runs on every binary in the app bundle. For large apps
  like WhatsApp (237 MB, many nested binaries) this walk blocks for several
  minutes. Apps will show the standard one-time Gatekeeper dialog instead.

HOMEBREW_NO_INSTALL_CLEANUP=1 — skips per-package cache cleanup after each
  install. A single brew cleanup already runs in ssr-sync afterwards.

mdimport — now runs in background (&) so Spotlight indexing never blocks
  the restore flow.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-12 11:52:24 +02:00
parent d849400f63
commit 1d18dd6a48
+19 -7
View File
@@ -141,17 +141,29 @@ ssr::brew::restore() {
# prompt individually for each package that needs admin privileges.
_ssr_sudo_keepalive_start
# Suppress per-app Spotlight indexing: mas would otherwise run mdimport
# after every App Store installation. One batch pass runs below instead.
# HOMEBREW_NO_QUARANTINE=1: skip the post-install `xattr -d com.apple.quarantine`
# pass that Homebrew runs on every cask. That xattr walk can block for
# several minutes on large apps (WhatsApp, Electron apps, …) because macOS
# Gatekeeper verifies every binary in the bundle. Apps will show a standard
# one-time Gatekeeper dialog on first launch instead — normal macOS behaviour.
#
# HOMEBREW_NO_INSTALL_CLEANUP=1: skip per-package cache cleanup after each
# install. A single `brew cleanup` runs in ssr-sync after the full bundle.
#
# MAS_NO_AUTO_INDEX=1: suppress per-app mdimport after every App Store app.
# One batch mdimport runs in the background below instead.
local rc=0
MAS_NO_AUTO_INDEX=1 brew bundle install --file="$brewfile" --verbose || rc=$?
HOMEBREW_NO_QUARANTINE=1 \
HOMEBREW_NO_INSTALL_CLEANUP=1 \
MAS_NO_AUTO_INDEX=1 \
brew bundle install --file="$brewfile" --verbose || rc=$?
_ssr_sudo_keepalive_stop
# Single batch Spotlight index of /Applications after all installs.
ssr::log "Indexing /Applications in Spotlight (one-time batch)"
mdimport /Applications 2>/dev/null || true
[[ -d "$HOME/Applications" ]] && mdimport "$HOME/Applications" 2>/dev/null || true
# Trigger Spotlight indexing in the background so it never blocks the restore.
ssr::log "Triggering background Spotlight index of /Applications"
mdimport /Applications &>/dev/null &
[[ -d "$HOME/Applications" ]] && mdimport "$HOME/Applications" &>/dev/null &
if [[ $rc -ne 0 ]]; then
ssr::warn "brew bundle install finished with errors (rc=$rc) — some packages were not installed."