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.
This commit is contained in:
Max Mueggler 2021-03-18 11:17:41 -04:00 committed by Markus Reiter
parent 571208c8ee
commit 23376bad75
No known key found for this signature in database
GPG Key ID: 245293B51702655B

View File

@ -110,6 +110,12 @@ module Cask
RMDIR_SH = <<~'BASH' RMDIR_SH = <<~'BASH'
set -euo pipefail 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 for path in "${@}"; do
symlink=true symlink=true
[[ -L "${path}" ]] || symlink=false [[ -L "${path}" ]] || symlink=false