From 809e82038894da86a49f634e2b798db21e09a852 Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Fri, 27 Oct 2017 16:53:22 -0300 Subject: [PATCH] Check that a single uninstall_* and zap stanzas is defined --- Library/Homebrew/cask/lib/hbc/audit.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index 5180c56889..e4349dc2d0 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -31,6 +31,7 @@ module Hbc check_generic_artifacts check_token_conflicts check_download + check_single_uninstall_zap self rescue StandardError => e odebug "#{e.message}\n#{e.backtrace.join("\n")}" @@ -48,6 +49,22 @@ module Hbc private + def check_single_uninstall_zap + odebug "Auditing single uninstall_* and zap stanzas" + + uninstalls = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::Uninstall) } + add_warning "there should be a single uninstall stanza" unless uninstalls.size <= 1 + + uninstalls_preflight = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.keys.include?("uninstall_preflight") } + add_warning "there should be a single uninstall_preflight stanza" unless uninstalls_preflight.size <= 1 + + uninstalls_postflight = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.keys.include?("uninstall_postflight") } + add_warning "there should be a single uninstall_postflight stanza" unless uninstalls_postflight.size <= 1 + + zaps = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::Zap) } + add_warning "there should be a single zap stanza" unless zaps.size <= 1 + end + def check_required_stanzas odebug "Auditing required stanzas" [:version, :sha256, :url, :homepage].each do |sym|