mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Use #count, rewrite warning, and add pre/postflight checks too
This commit is contained in:
parent
809e820388
commit
9b6b0bfed7
@ -31,6 +31,7 @@ module Hbc
|
|||||||
check_generic_artifacts
|
check_generic_artifacts
|
||||||
check_token_conflicts
|
check_token_conflicts
|
||||||
check_download
|
check_download
|
||||||
|
check_single_pre_postflight
|
||||||
check_single_uninstall_zap
|
check_single_uninstall_zap
|
||||||
self
|
self
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
@ -49,20 +50,24 @@ module Hbc
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def check_single_pre_postflight
|
||||||
|
odebug "Auditing preflight and postflight stanzas"
|
||||||
|
|
||||||
|
add_warning "only a single preflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:preflight) } > 1
|
||||||
|
|
||||||
|
add_warning "only a single postflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.key?(:postflight) } > 1
|
||||||
|
end
|
||||||
|
|
||||||
def check_single_uninstall_zap
|
def check_single_uninstall_zap
|
||||||
odebug "Auditing single uninstall_* and zap stanzas"
|
odebug "Auditing single uninstall_* and zap stanzas"
|
||||||
|
|
||||||
uninstalls = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::Uninstall) }
|
add_warning "only a single uninstall stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Uninstall) } > 1
|
||||||
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 "only a single uninstall_preflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:uninstall_preflight) } > 1
|
||||||
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 "only a single uninstall_postflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.key?(:uninstall_postflight) } > 1
|
||||||
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 "only a single zap stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Zap) } > 1
|
||||||
add_warning "there should be a single zap stanza" unless zaps.size <= 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_required_stanzas
|
def check_required_stanzas
|
||||||
|
Loading…
x
Reference in New Issue
Block a user