mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Detect Apache mirror system and parse out the closest mirror.
All Apache Formulae should be updated to use the closer.vgi script to specify downloads rather than a random mirror that could be out of date or compromised. Apache's closer.cgi does periodic health checks. The base URL for the mirror system is http://www.apache.org/dyn/closer.cgi?path=#{filepath} e.g.: http://www.apache.org/dyn/closer.cgi?path=/couchdb/1.0.3/apache-couchdb-1.0.3.tar.gz Note: The addition of the "Actually downloading..." message is sub-optimal as the message should probably be emitted in _fetch() rather than fetch(), but I didn't want to change the way Homebrew works today, so I'm leaving this for mxcl & team to sort out or adopt :)
This commit is contained in:
parent
e2b21b0b4a
commit
c576f4088c
@ -126,6 +126,23 @@ private
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Detect and download from Apache Mirror
|
||||||
|
class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
|
||||||
|
def _fetch
|
||||||
|
# Fetch mirror list site
|
||||||
|
require 'open-uri'
|
||||||
|
mirror_list = open(@url).read()
|
||||||
|
|
||||||
|
# Parse out suggested mirror
|
||||||
|
# Yep, this is ghetto, grep the first <strong></strong> element content
|
||||||
|
mirror_url = mirror_list[/<strong>([^<]+)/, 1]
|
||||||
|
|
||||||
|
ohai "Actually downloading from mirror: #{mirror_url}"
|
||||||
|
# Start download from that mirror
|
||||||
|
curl mirror_url, '-o', @tarball_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Download via an HTTP POST.
|
# Download via an HTTP POST.
|
||||||
# Query parameters on the URL are converted into POST parameters
|
# Query parameters on the URL are converted into POST parameters
|
||||||
class CurlPostDownloadStrategy < CurlDownloadStrategy
|
class CurlPostDownloadStrategy < CurlDownloadStrategy
|
||||||
@ -514,6 +531,7 @@ def detect_download_strategy url
|
|||||||
when %r[^https?://(.+?\.)?googlecode\.com/svn] then SubversionDownloadStrategy
|
when %r[^https?://(.+?\.)?googlecode\.com/svn] then SubversionDownloadStrategy
|
||||||
when %r[^https?://(.+?\.)?sourceforge\.net/svnroot/] then SubversionDownloadStrategy
|
when %r[^https?://(.+?\.)?sourceforge\.net/svnroot/] then SubversionDownloadStrategy
|
||||||
when %r[^http://svn.apache.org/repos/] then SubversionDownloadStrategy
|
when %r[^http://svn.apache.org/repos/] then SubversionDownloadStrategy
|
||||||
|
when %r[^http://www.apache.org/dyn/closer.cgi] then CurlApacheMirrorDownloadStrategy
|
||||||
# Otherwise just try to download
|
# Otherwise just try to download
|
||||||
else CurlDownloadStrategy
|
else CurlDownloadStrategy
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user