From 571208c8eeef8426372d14144761506eb3815a55 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 28 Mar 2021 01:50:15 +0100 Subject: [PATCH] Only call `find` on directories. --- Library/Homebrew/cask/pkg.rb | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/cask/pkg.rb b/Library/Homebrew/cask/pkg.rb index 0a63d49df1..d999c35f21 100644 --- a/Library/Homebrew/cask/pkg.rb +++ b/Library/Homebrew/cask/pkg.rb @@ -111,27 +111,34 @@ module Cask set -euo pipefail for path in "${@}"; do - if [[ ! -e "${path}" ]]; then + symlink=true + [[ -L "${path}" ]] || symlink=false + + directory=false + if [[ -d "${path}" ]]; then + directory=true + + if [[ -e "${path}/.DS_Store" ]]; then + /bin/rm -- "${path}/.DS_Store" + fi + + # Some packages leave broken symlinks around; we clean them out before + # attempting to `rmdir` to prevent extra cruft from accumulating. + /usr/bin/find -f "${path}" -- -mindepth 1 -maxdepth 1 -type l ! -exec /bin/test -e {} \; -delete + elif ! ${symlink} && [[ ! -e "${path}" ]]; then + # Skip paths that don't exists and aren't a broken symlink. continue fi - if [[ -e "${path}/.DS_Store" ]]; then - /bin/rm -f "${path}/.DS_Store" - fi - - # Some packages leave broken symlinks around; we clean them out before - # attempting to `rmdir` to prevent extra cruft from accumulating. - /usr/bin/find "${path}" -mindepth 1 -maxdepth 1 -type l ! -exec /bin/test -e {} \; -delete - - if [[ -L "${path}" ]]; then + if ${symlink}; then # Delete directory symlink. - /bin/rm "${path}" - elif [[ -d "${path}" ]]; then + /bin/rm -- "${path}" + elif ${directory}; then # Delete directory if empty. - /usr/bin/find "${path}" -maxdepth 0 -type d -empty -exec /bin/rmdir {} \; + /usr/bin/find -f "${path}" -- -maxdepth 0 -type d -empty -exec /bin/rmdir -- {} \; else # Try `rmdir` anyways to show a proper error. - /bin/rmdir "${path}" + /bin/rmdir -- "${path}" fi done BASH