From 23376bad7512e5e66869e512aca1e0177c51a54f Mon Sep 17 00:00:00 2001 From: Max Mueggler Date: Thu, 18 Mar 2021 11:17:41 -0400 Subject: [PATCH] Speed up cask pkg uninstallation when there's many directories to delete. Results in an order of magnitude speedup for uninstalling large packages such as mactex. --- Library/Homebrew/cask/pkg.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Library/Homebrew/cask/pkg.rb b/Library/Homebrew/cask/pkg.rb index d999c35f21..47134fbc42 100644 --- a/Library/Homebrew/cask/pkg.rb +++ b/Library/Homebrew/cask/pkg.rb @@ -110,6 +110,12 @@ module Cask RMDIR_SH = <<~'BASH' set -euo pipefail + # Try removing as many empty directories as possible with a single + # `rmdir` call to avoid or at least speed up the loop below. + if /bin/rmdir -- "${@}" &>/dev/null; then + exit + fi + for path in "${@}"; do symlink=true [[ -L "${path}" ]] || symlink=false