From c301b2704326bcc2867f07210ad3cb7b0d9de0ce Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Thu, 31 Jul 2014 10:02:57 -0400 Subject: [PATCH] force permissions and delete ACLs if rmtree fails This logic is ugly as the installation directory will be left in a mangled state if it fails partway through. However, the same is true when `rmtree` fails partway through, which this code is intended to minimize. References: #5504 --- lib/cask/installer.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/cask/installer.rb b/lib/cask/installer.rb index 862807bc8fd40..f01aee1e22d7b 100644 --- a/lib/cask/installer.rb +++ b/lib/cask/installer.rb @@ -125,7 +125,16 @@ def uninstall_artifacts def purge_files odebug "Purging files" if @cask.destination_path.exist? - @cask.destination_path.rmtree + begin + @cask.destination_path.rmtree + rescue + # in case of permissions problems + if @cask.destination_path.exist? + @command.run('/bin/chmod', :args => ['-R', '--', 'u+rwx', @cask.destination_path]) + @command.run('/bin/chmod', :args => ['-R', '-N', @cask.destination_path]) + @cask.destination_path.rmtree + end + end end @cask.caskroom_path.rmdir_if_possible end