Revert install_artifacts if one artifact fails to install.

This commit is contained in:
Markus Reiter 2016-12-04 23:14:35 +01:00
parent e6d9248787
commit 5785f54f4b

View File

@ -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