Only call find on directories.

This commit is contained in:
Markus Reiter 2021-03-28 01:50:15 +01:00
parent 2bd0b6ee61
commit 571208c8ee
No known key found for this signature in database
GPG Key ID: 245293B51702655B

View File

@ -111,27 +111,34 @@ module Cask
set -euo pipefail set -euo pipefail
for path in "${@}"; do 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 continue
fi fi
if [[ -e "${path}/.DS_Store" ]]; then if ${symlink}; 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
# Delete directory symlink. # Delete directory symlink.
/bin/rm "${path}" /bin/rm -- "${path}"
elif [[ -d "${path}" ]]; then elif ${directory}; then
# Delete directory if empty. # 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 else
# Try `rmdir` anyways to show a proper error. # Try `rmdir` anyways to show a proper error.
/bin/rmdir "${path}" /bin/rmdir -- "${path}"
fi fi
done done
BASH BASH