From 6aa4145e3cba9ef5011eb5a7d320acfee90f1a19 Mon Sep 17 00:00:00 2001 From: Seeker Date: Wed, 24 Feb 2021 03:23:15 -0800 Subject: [PATCH] bump-cask-pr: edit `fetch_resource` to reduce code duplication `fetch_resource` now returns a SHA-256 string instead of file path --- Library/Homebrew/dev-cmd/bump-cask-pr.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/dev-cmd/bump-cask-pr.rb b/Library/Homebrew/dev-cmd/bump-cask-pr.rb index a3c1b748ba..cd4ca2cb35 100644 --- a/Library/Homebrew/dev-cmd/bump-cask-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-cask-pr.rb @@ -126,14 +126,11 @@ module Homebrew tmp_url = tmp_cask.url.to_s if old_hash != :no_check - if new_hash.nil? - resource_path = fetch_resource(cask, new_version, tmp_url) - Utils::Tar.validate_file(resource_path) - new_hash = resource_path.sha256 - end + new_hash = fetch_resource(cask, new_version, tmp_url) if new_hash.nil? if tmp_contents.include?("Hardware::CPU.intel?") - other_contents = tmp_contents.gsub("Hardware::CPU.intel?", (!Hardware::CPU.intel?).to_s) + other_intel = !Hardware::CPU.intel? + other_contents = tmp_contents.gsub("Hardware::CPU.intel?", other_intel.to_s) replacement_pairs << fetch_cask(other_contents, new_version) end end @@ -186,7 +183,10 @@ module Homebrew resource.url(url, specs) resource.owner = Resource.new(cask.token) resource.version = version - resource.fetch + + resource_path = resource.fetch + Utils::Tar.validate_file(resource_path) + resource_path.sha256 end def fetch_cask(contents, version, config: nil) @@ -194,11 +194,7 @@ module Homebrew cask.config = config if config.present? url = cask.url.to_s old_hash = cask.sha256.to_s - - resource_path = fetch_resource(cask, version, url) - Utils::Tar.validate_file(resource_path) - new_hash = resource_path.sha256 - + new_hash = fetch_resource(cask, version, url) [old_hash, new_hash] end