Only call find on directories.
This commit is contained in:
parent
2bd0b6ee61
commit
571208c8ee
@ -111,27 +111,34 @@ module Cask
|
||||
set -euo pipefail
|
||||
|
||||
for path in "${@}"; do
|
||||
if [[ ! -e "${path}" ]]; then
|
||||
continue
|
||||
fi
|
||||
symlink=true
|
||||
[[ -L "${path}" ]] || symlink=false
|
||||
|
||||
directory=false
|
||||
if [[ -d "${path}" ]]; then
|
||||
directory=true
|
||||
|
||||
if [[ -e "${path}/.DS_Store" ]]; then
|
||||
/bin/rm -f "${path}/.DS_Store"
|
||||
/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 "${path}" -mindepth 1 -maxdepth 1 -type l ! -exec /bin/test -e {} \; -delete
|
||||
/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 [[ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user