From 7a22cda8ddc5dcd8304beab7767132bd4dcdafb9 Mon Sep 17 00:00:00 2001 From: Lucendio Date: Wed, 17 Mar 2021 00:35:08 +0100 Subject: [PATCH 1/2] Fix broken rmdir script Unfortunately, the removal shell script introduced in #10860 does not handle paths very well that dont exist, e.g. * `find` runs before its `-exec` test, thus throws `find: "${path}": No such file or directory` * it seem that `/bin/rmdir` is intended to break is certain cases, thus `-f` is not desired. so, if `${path}` does not exist, it'll still break, which is most likely not one of those cases. This change reintroduces a check for existence. This way, it is ensured that there is actually a directory to be removed when invoking the script. --- Library/Homebrew/cask/pkg.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Library/Homebrew/cask/pkg.rb b/Library/Homebrew/cask/pkg.rb index ca9cf34b75..ea7b0f3cb6 100644 --- a/Library/Homebrew/cask/pkg.rb +++ b/Library/Homebrew/cask/pkg.rb @@ -135,6 +135,8 @@ module Cask sig { params(path: T.any(Pathname, T::Array[Pathname])).void } def rmdir(path) + return unless path.exist? + @command.run!( "/usr/bin/xargs", args: ["-0", "--", "/bin/bash", "-c", RMDIR_SH, "--"], From aceb02125461be3f2224fa31fa5b9c3090d5d2d7 Mon Sep 17 00:00:00 2001 From: Lucendio Date: Wed, 17 Mar 2021 01:33:56 +0100 Subject: [PATCH 2/2] Move existence check into helper script This way, it'll run as `root`, too. --- Library/Homebrew/cask/pkg.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/pkg.rb b/Library/Homebrew/cask/pkg.rb index ea7b0f3cb6..0a63d49df1 100644 --- a/Library/Homebrew/cask/pkg.rb +++ b/Library/Homebrew/cask/pkg.rb @@ -111,6 +111,10 @@ module Cask set -euo pipefail for path in "${@}"; do + if [[ ! -e "${path}" ]]; then + continue + fi + if [[ -e "${path}/.DS_Store" ]]; then /bin/rm -f "${path}/.DS_Store" fi @@ -135,8 +139,6 @@ module Cask sig { params(path: T.any(Pathname, T::Array[Pathname])).void } def rmdir(path) - return unless path.exist? - @command.run!( "/usr/bin/xargs", args: ["-0", "--", "/bin/bash", "-c", RMDIR_SH, "--"],