aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc
diff options
context:
space:
mode:
authorMarkus Reiter2017-01-23 17:17:50 +0100
committerGitHub2017-01-23 17:17:50 +0100
commite59ada508727f11464595893783beb914c26f60b (patch)
tree795520e45d29052df65c56503c4a6d2983334ef1 /Library/Homebrew/cask/lib/hbc
parent44596696175bef38f3cde07e4f45285c322996b8 (diff)
parent2076b494a6233630025acd45d9a5766bd6bb785d (diff)
downloadbrew-1.1.8.tar.bz2
Merge pull request #1894 from reitermarkus/appcast-checkpoint1.1.8
Add internal command to calculate appcast checkpoint.
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc')
-rw-r--r--Library/Homebrew/cask/lib/hbc/audit.rb19
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb1
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb61
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl/appcast.rb16
4 files changed, 87 insertions, 10 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb
index 955ecdbb0..12cefb939 100644
--- a/Library/Homebrew/cask/lib/hbc/audit.rb
+++ b/Library/Homebrew/cask/lib/hbc/audit.rb
@@ -133,20 +133,19 @@ module Hbc
def check_appcast_checkpoint_accuracy
odebug "Verifying appcast checkpoint is accurate"
- result = @command.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, cask.appcast], print_stderr: false)
- if result.success?
- processed_appcast_text = result.stdout.gsub(%r{<pubDate>[^<]*</pubDate>}, "")
- # This step is necessary to replicate running `sed` from the command line
- processed_appcast_text << "\n" unless processed_appcast_text.end_with?("\n")
+ result = cask.appcast.calculate_checkpoint
+
+ actual_checkpoint = result[:checkpoint]
+
+ if actual_checkpoint.nil?
+ add_warning "error retrieving appcast: #{result[:command_result].stderr}"
+ else
expected = cask.appcast.checkpoint
- actual = Digest::SHA2.hexdigest(processed_appcast_text)
- add_warning <<-EOS.undent unless expected == actual
+ add_warning <<-EOS.undent unless expected == actual_checkpoint
appcast checkpoint mismatch
Expected: #{expected}
- Actual: #{actual}
+ Actual: #{actual_checkpoint}
EOS
- else
- add_warning "error retrieving appcast: #{result.stderr}"
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb
index 42c3982ba..36fae3034 100644
--- a/Library/Homebrew/cask/lib/hbc/cli.rb
+++ b/Library/Homebrew/cask/lib/hbc/cli.rb
@@ -23,6 +23,7 @@ require "hbc/cli/zap"
require "hbc/cli/internal_use_base"
require "hbc/cli/internal_audit_modified_casks"
+require "hbc/cli/internal_appcast_checkpoint"
require "hbc/cli/internal_checkurl"
require "hbc/cli/internal_dump"
require "hbc/cli/internal_help"
diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
new file mode 100644
index 000000000..790e917b2
--- /dev/null
+++ b/Library/Homebrew/cask/lib/hbc/cli/internal_appcast_checkpoint.rb
@@ -0,0 +1,61 @@
+module Hbc
+ class CLI
+ class InternalAppcastCheckpoint < InternalUseBase
+ def self.run(*args)
+ calculate = args.include? "--calculate"
+ cask_tokens = cask_tokens_from(args)
+ raise CaskUnspecifiedError if cask_tokens.empty?
+
+ if cask_tokens.all? { |t| t =~ %r{^https?://} && t !~ /\.rb$/ }
+ appcask_checkpoint_for_url(cask_tokens)
+ else
+ appcask_checkpoint(cask_tokens, calculate)
+ end
+ end
+
+ def self.appcask_checkpoint_for_url(urls)
+ urls.each do |url|
+ appcast = DSL::Appcast.new(url)
+ puts appcast.calculate_checkpoint[:checkpoint]
+ end
+ end
+
+ def self.appcask_checkpoint(cask_tokens, calculate)
+ count = 0
+
+ cask_tokens.each do |cask_token|
+ cask = Hbc.load(cask_token)
+
+ if cask.appcast.nil?
+ opoo "Cask '#{cask}' is missing an `appcast` stanza."
+ else
+ if calculate
+ result = cask.appcast.calculate_checkpoint
+
+ checkpoint = result[:checkpoint]
+ else
+ checkpoint = cask.appcast.checkpoint
+ end
+
+ if checkpoint.nil?
+ onoe "Could not retrieve `appcast` checkpoint for cask '#{cask}': #{result[:command_result].stderr}"
+ else
+ puts cask_tokens.count > 1 ? "#{checkpoint} #{cask}": checkpoint
+ count += 1
+ end
+ end
+ end
+
+ count == cask_tokens.count
+ end
+
+ def self.help
+ "prints or calculates a given Cask's or URL's appcast checkpoint"
+ end
+
+ def self.needs_init?
+ true
+ end
+ end
+ end
+end
diff --git a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
index 2f1245d3d..e27870622 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl/appcast.rb
@@ -1,3 +1,5 @@
+require "hbc/system_command"
+
module Hbc
class DSL
class Appcast
@@ -9,6 +11,20 @@ module Hbc
@checkpoint = @parameters[:checkpoint]
end
+ def calculate_checkpoint
+ result = SystemCommand.run("/usr/bin/curl", args: ["--compressed", "--location", "--user-agent", URL::FAKE_USER_AGENT, @uri], print_stderr: false)
+
+ checkpoint = if result.success?
+ processed_appcast_text = result.stdout.gsub(%r{<pubDate>[^<]*</pubDate>}m, "")
+ Digest::SHA2.hexdigest(processed_appcast_text)
+ end
+
+ {
+ checkpoint: checkpoint,
+ command_result: result,
+ }
+ end
+
def to_yaml
[@uri, @parameters].to_yaml
end