Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

software_spec: Add HOMEBREW_BOTTLE_DEFAULT_DOMAIN as a fallback option #10671

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Library/Homebrew/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ module EnvConfig
},
HOMEBREW_BOTTLE_DOMAIN: {
description: "Use this URL as the download mirror for bottles. " \
"If bottles at that URL are temporarily unavailable, " \
"the default bottle domain will be used as a fallback mirror. " \
"For example, `HOMEBREW_BOTTLE_DOMAIN=http://localhost:8080` will cause all bottles to " \
"download from the prefix `http://localhost:8080/`.",
"download from the prefix `http://localhost:8080/`. " \
"If bottles are not available at `HOMEBREW_BOTTLE_DOMAIN` " \
"they will be downloaded from the default bottle domain.",
default_text: "macOS: `https://homebrew.bintray.com/`, " \
"Linux: `https://linuxbrew.bintray.com/`.",
default: HOMEBREW_BOTTLE_DEFAULT_DOMAIN,
Expand Down
15 changes: 14 additions & 1 deletion Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# frozen_string_literal: true

require "resource"
require "download_strategy"
require "checksum"
require "version"
require "options"
Expand Down Expand Up @@ -292,7 +293,7 @@ def extname

attr_reader :name, :resource, :prefix, :cellar, :rebuild

def_delegators :resource, :url, :fetch, :verify_download_integrity
def_delegators :resource, :url, :verify_download_integrity
def_delegators :resource, :cached_download, :clear_cache

def initialize(formula, spec)
Expand All @@ -314,6 +315,18 @@ def initialize(formula, spec)
@rebuild = spec.rebuild
end

def fetch(verify_download_integrity: true)
# add the default bottle domain as a fallback mirror
if @resource.download_strategy == CurlDownloadStrategy &&
@resource.url.start_with?(Homebrew::EnvConfig.bottle_domain)
fallback_url = @resource.url
.sub(/^#{Regexp.escape(Homebrew::EnvConfig.bottle_domain)}/,
HOMEBREW_BOTTLE_DEFAULT_DOMAIN)
@resource.mirror(fallback_url) if [@resource.url, *@resource.mirrors].exclude?(fallback_url)
end
@resource.fetch(verify_download_integrity: verify_download_integrity)
end

def compatible_locations?
@spec.compatible_locations?
end
Expand Down
2 changes: 1 addition & 1 deletion docs/Manpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ example, run `export HOMEBREW_NO_INSECURE_REDIRECT=1` rather than just
<br>If set, use Bootsnap to speed up repeated `brew` calls. A no-op when using Homebrew's vendored, relocatable Ruby on macOS (as it doesn't work).

- `HOMEBREW_BOTTLE_DOMAIN`
<br>Use this URL as the download mirror for bottles. For example, `HOMEBREW_BOTTLE_DOMAIN=http://localhost:8080` will cause all bottles to download from the prefix `http://localhost:8080/`.
<br>Use this URL as the download mirror for bottles. If bottles at that URL are temporarily unavailable, the default bottle domain will be used as a fallback mirror. For example, `HOMEBREW_BOTTLE_DOMAIN=http://localhost:8080` will cause all bottles to download from the prefix `http://localhost:8080/`. If bottles are not available at `HOMEBREW_BOTTLE_DOMAIN` they will be downloaded from the default bottle domain.

*Default:* macOS: `https://homebrew.bintray.com/`, Linux: `https://linuxbrew.bintray.com/`.

Expand Down
2 changes: 1 addition & 1 deletion manpages/brew.1
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,7 @@ If set, use Bootsnap to speed up repeated \fBbrew\fR calls\. A no\-op when using
\fBHOMEBREW_BOTTLE_DOMAIN\fR
.
.br
Use this URL as the download mirror for bottles\. For example, \fBHOMEBREW_BOTTLE_DOMAIN=http://localhost:8080\fR will cause all bottles to download from the prefix \fBhttp://localhost:8080/\fR\.
Use this URL as the download mirror for bottles\. If bottles at that URL are temporarily unavailable, the default bottle domain will be used as a fallback mirror\. For example, \fBHOMEBREW_BOTTLE_DOMAIN=http://localhost:8080\fR will cause all bottles to download from the prefix \fBhttp://localhost:8080/\fR\. If bottles are not available at \fBHOMEBREW_BOTTLE_DOMAIN\fR they will be downloaded from the default bottle domain\.
.
.IP
\fIDefault:\fR macOS: \fBhttps://homebrew\.bintray\.com/\fR, Linux: \fBhttps://linuxbrew\.bintray\.com/\fR\.
Expand Down