Library/Homebrew/dev-cmd/pull.rb
def verify_bintray_published(formulae_names)
    return if formulae_names.empty?

    if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"]
      raise "Need to load formulae to verify their publication!"
    end

    ohai "Verifying bottles published on Bintray"
    formulae = formulae_names.map { |n| Formula[n] }
    max_retries = 300 # shared among all bottles
    poll_retry_delay_seconds = 2

    HOMEBREW_CACHE.cd do
      formulae.each do |f|
        retry_count = 0
        wrote_dots = false
        # Choose arbitrary bottle just to get the host/port for Bintray right
        jinfo = FormulaInfoFromJson.lookup(f.full_name)
        unless jinfo
          opoo "Cannot publish bottle: Failed reading info for formula #{f.full_name}"
          next
        end
        bottle_info = jinfo.bottle_info_any
        unless bottle_info
          opoo "No bottle defined in formula #{f.full_name}"
          next
        end

        # Poll for publication completion using a quick partial HEAD, to avoid spurious error messages
        # 401 error is normal while file is still in async publishing process
        url = URI(bottle_info.url)
        puts "Verifying bottle: #{File.basename(url.path)}"
        http = Net::HTTP.new(url.host, url.port)
        http.use_ssl = true
        retry_count = 0
        http.start do
          loop do
            req = Net::HTTP::Head.new bottle_info.url
            req.initialize_http_header "User-Agent" => HOMEBREW_USER_AGENT_RUBY
            res = http.request req
            break if res.is_a?(Net::HTTPSuccess) || res.code == "302"

            unless res.is_a?(Net::HTTPClientError)
              raise "Failed to find published #{f} bottle at #{url} (#{res.code} #{res.message})!"
            end

            if retry_count >= max_retries
              raise "Failed to find published #{f} bottle at #{url}!"
            end

            print(wrote_dots ? "." : "Waiting on Bintray.")
            wrote_dots = true
            sleep poll_retry_delay_seconds
            retry_count += 1
          end
        end

        # Actual download and verification
        # We do a retry on this, too, because sometimes the external curl will fail even
        # when the prior HEAD has succeeded.
        puts "\n" if wrote_dots
        filename = File.basename(url.path)
        curl_retry_delay_seconds = 4
        max_curl_retries = 1
        retry_count = 0
        # We're in the cache; make sure to force re-download
        loop do
          begin
            curl_download url, to: filename
            break
          rescue
            if retry_count >= max_curl_retries
              raise "Failed to download #{f} bottle from #{url}!"
            end

            puts "curl download failed; retrying in #{curl_retry_delay_seconds} sec"
            sleep curl_retry_delay_seconds
            curl_retry_delay_seconds *= 2
            retry_count += 1
          end
        end
        checksum = Checksum.new(:sha256, bottle_info.sha256)
        Pathname.new(filename).verify_checksum(checksum)
      end
    end
  end
# Verifies that formulae have been published on Bintray by downloading a bottle file
# for each one. Blocks until the published files are available.
# Raises an error if the verification fails.
# This does not currently work for `brew pull`, because it may have cached the old
# version of a formula.
Verifies that formulae have been published on Bintray by downloading a bottle file
for each one. Blocks until the published files are available.
Raises an error if the verification fails.
This does not currently work for `brew pull`, because it may have cached the old
version of a formula.
Verifies that formulae have been published on Bintray by downloading a bottle file for each one . Blocks until the published files are available . Raises an error if the verification fails . This does not currently work for ` brew pull ` because it may have cached the old version of a formula .
def verify_bintray_published(formulae_names)
    return if formulae_names.empty?
    if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"]
      raise "Need to load formulae to verify their publication!"
    end
    ohai "Verifying bottles published on Bintray"
    formulae = formulae_names.map { |n| Formula[n] }
    max_retries = 300 
    poll_retry_delay_seconds = 2
    HOMEBREW_CACHE.cd do
      formulae.each do |f|
        retry_count = 0
        wrote_dots = false
        jinfo = FormulaInfoFromJson.lookup(f.full_name)
        unless jinfo
          opoo "Cannot publish bottle: Failed reading info for formula #{f.full_name}"
          next
        end
        bottle_info = jinfo.bottle_info_any
        unless bottle_info
          opoo "No bottle defined in formula #{f.full_name}"
          next
        end
        url = URI(bottle_info.url)
        puts "Verifying bottle: #{File.basename(url.path)}"
        http = Net::HTTP.new(url.host, url.port)
        http.use_ssl = true
        retry_count = 0
        http.start do
          loop do
            req = Net::HTTP::Head.new bottle_info.url
            req.initialize_http_header "User-Agent" => HOMEBREW_USER_AGENT_RUBY
            res = http.request req
            break if res.is_a?(Net::HTTPSuccess) || res.code == "302"
            unless res.is_a?(Net::HTTPClientError)
              raise "Failed to find published #{f} bottle at #{url} (#{res.code} #{res.message})!"
            end
            if retry_count >= max_retries
              raise "Failed to find published #{f} bottle at #{url}!"
            end
            print(wrote_dots ? "." : "Waiting on Bintray.")
            wrote_dots = true
            sleep poll_retry_delay_seconds
            retry_count += 1
          end
        end
        puts "\n" if wrote_dots
        filename = File.basename(url.path)
        curl_retry_delay_seconds = 4
        max_curl_retries = 1
        retry_count = 0
        loop do
          begin
            curl_download url, to: filename
            break
          rescue
            if retry_count >= max_curl_retries
              raise "Failed to download #{f} bottle from #{url}!"
            end
            puts "curl download failed; retrying in #{curl_retry_delay_seconds} sec"
            sleep curl_retry_delay_seconds
            curl_retry_delay_seconds *= 2
            retry_count += 1
          end
        end
        checksum = Checksum.new(:sha256, bottle_info.sha256)
        Pathname.new(filename).verify_checksum(checksum)
      end
    end
  end
def verify_bintray_published ( formulae_names ) return if formulae_names . empty? if ENV [ "HOMEBREW_DISABLE_LOAD_FORMULA" ] raise "Need to load formulae to verify their publication!" end ohai "Verifying bottles published on Bintray" formulae = formulae_names . map { | n | Formula [ n ] } max_retries = 300 poll_retry_delay_seconds = 2 HOMEBREW_CACHE . cd do formulae . each do | f | retry_count = 0 wrote_dots = false jinfo = FormulaInfoFromJson . lookup ( f . full_name ) unless jinfo opoo "Cannot publish bottle: Failed reading info for formula #{f.full_name}" next end bottle_info = jinfo . bottle_info_any unless bottle_info opoo "No bottle defined in formula #{f.full_name}" next end url = URI ( bottle_info . url ) puts "Verifying bottle: #{File.basename(url.path)}" http = Net :: HTTP . new ( url . host , url . port ) http . use_ssl = true retry_count = 0 http . start do loop do req = Net :: HTTP :: Head . new bottle_info . url req . initialize_http_header "User-Agent" => HOMEBREW_USER_AGENT_RUBY res = http . request req break if res . is_a? ( Net :: HTTPSuccess ) || res . code == "302" unless res . is_a? ( Net :: HTTPClientError ) raise "Failed to find published #{f} bottle at #{url} (#{res.code} #{res.message})!" end if retry_count >= max_retries raise "Failed to find published #{f} bottle at #{url}!" end print ( wrote_dots ? "." : "Waiting on Bintray." ) wrote_dots = true sleep poll_retry_delay_seconds retry_count += 1 end end puts "\n" if wrote_dots filename = File . basename ( url . path ) curl_retry_delay_seconds = 4 max_curl_retries = 1 retry_count = 0 loop do begin curl_download url , to : filename break rescue if retry_count >= max_curl_retries raise "Failed to download #{f} bottle from #{url}!" end puts "curl download failed; retrying in #{curl_retry_delay_seconds} sec" sleep curl_retry_delay_seconds curl_retry_delay_seconds *= 2 retry_count += 1 end end checksum = Checksum . new ( :sha256 , bottle_info . sha256 ) Pathname . new ( filename ) . verify_checksum ( checksum ) end end end
Verifies that formulae have been published on Bintray by downloading a bottle file
for each one.
Verifies that formulae have been published on Bintray by downloading a bottle file for each one .
# shared among all bottles # Choose arbitrary bottle just to get the host/port for Bintray right # Poll for publication completion using a quick partial HEAD, to avoid spurious error messages # 401 error is normal while file is still in async publishing process # Actual download and verification # We do a retry on this, too, because sometimes the external curl will fail even # when the prior HEAD has succeeded. # We're in the cache; make sure to force re-download
formulae_names