From 2a21991b1fc8039bfa0c950e439db5a725b62b42 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 16 Feb 2017 17:10:40 +0100 Subject: [PATCH] Make sure `uninstall` is called before artifacts are removed. --- Library/Homebrew/cask/lib/hbc/installer.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index cafc9d8b9e..b86f3264d2 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -318,7 +318,13 @@ module Hbc def uninstall_artifacts odebug "Un-installing artifacts" artifacts = Artifact.for_cask(@cask, command: @command, force: force) + + # Make sure the `uninstall` stanza is run first, as it + # may depend on other artifacts still being installed. + artifacts = artifacts.sort_by { |a| a.is_a?(Artifact::Uninstall) ? -1 : 1 } + odebug "#{artifacts.length} artifact/s defined", artifacts + artifacts.each do |artifact| next unless artifact.respond_to?(:uninstall_phase) odebug "Un-installing artifact of class #{artifact.class}"