Retry GitHub Packages manifest download if invalid.

This commit is contained in:
Mike McQuaid 2021-10-22 10:41:35 +01:00
parent 6de841cd73
commit f781f28d6d
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829

View File

@ -323,6 +323,8 @@ class Bottle
@resource.version = formula.pkg_version @resource.version = formula.pkg_version
@resource.checksum = tag_spec.checksum @resource.checksum = tag_spec.checksum
@fetch_tab_retried = false
root_url(spec.root_url, spec.root_url_specs) root_url(spec.root_url, spec.root_url_specs)
end end
@ -338,6 +340,7 @@ class Bottle
def clear_cache def clear_cache
@resource.clear_cache @resource.clear_cache
github_packages_manifest_resource&.clear_cache github_packages_manifest_resource&.clear_cache
@fetch_tab_retried = false
end end
def compatible_locations? def compatible_locations?
@ -360,23 +363,31 @@ class Bottle
github_packages_manifest_resource.fetch(verify_download_integrity: false) github_packages_manifest_resource.fetch(verify_download_integrity: false)
begin begin
JSON.parse(github_packages_manifest_resource.cached_download.read) github_packages_manifest_resource_tab(github_packages_manifest_resource)
rescue JSON::ParserError rescue RuntimeError => e
raise DownloadError.new( raise DownloadError.new(github_packages_manifest_resource, e)
github_packages_manifest_resource,
RuntimeError.new("The downloaded GitHub Packages manifest was corrupted or modified (it is not valid JSON):"\
"\n#{github_packages_manifest_resource.cached_download}"),
)
end end
rescue DownloadError rescue DownloadError
raise unless fallback_on_error raise unless fallback_on_error
retry
rescue ArgumentError
raise if @fetch_tab_retried
@fetch_tab_retried = true
github_packages_manifest_resource.clear_cache
retry retry
end end
def tab_attributes def tab_attributes
return {} unless github_packages_manifest_resource&.downloaded? return {} unless github_packages_manifest_resource&.downloaded?
github_packages_manifest_resource_tab(github_packages_manifest_resource)
end
private
def github_packages_manifest_resource_tab(github_packages_manifest_resource)
manifest_json = github_packages_manifest_resource.cached_download.read manifest_json = github_packages_manifest_resource.cached_download.read
json = begin json = begin
@ -411,8 +422,6 @@ class Bottle
end end
end end
private
def github_packages_manifest_resource def github_packages_manifest_resource
return if @resource.download_strategy != CurlGitHubPackagesDownloadStrategy return if @resource.download_strategy != CurlGitHubPackagesDownloadStrategy