From 5785f54f4bd48dca58a7550af48217d4c6372ad2 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 4 Dec 2016 23:14:35 +0100 Subject: [PATCH] Revert `install_artifacts` if one artifact fails to install. --- Library/Homebrew/cask/lib/hbc/installer.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index df7554cc51..5176143d7a 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -132,14 +132,29 @@ module Hbc end def install_artifacts + already_installed_artifacts = [] + options = { command: @command, force: force } + odebug "Installing artifacts" artifacts = Artifact.for_cask(@cask) odebug "#{artifacts.length} artifact/s defined", artifacts + artifacts.each do |artifact| odebug "Installing artifact of class #{artifact}" - options = { command: @command, force: force } + already_installed_artifacts.unshift(artifact) artifact.new(@cask, options).install_phase end + rescue StandardError => e + begin + ofail e.message + already_installed_artifacts.each do |artifact| + odebug "Reverting installation of artifact of class #{artifact}" + artifact.new(@cask, options).uninstall_phase + end + ensure + purge_versioned_files + raise e.class, "An error occured during installation of Cask #{@cask}: #{e.message}" + end end # TODO: move dependencies to a separate class