CurlApacheMirrorDownloadStrategy: fetch mirrors in JSON format
Closes Homebrew/homebrew#16457.
This commit is contained in:
parent
8135ed6528
commit
0a9f5c6867
@ -148,19 +148,16 @@ end
|
|||||||
# Detect and download from Apache Mirror
|
# Detect and download from Apache Mirror
|
||||||
class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
|
class CurlApacheMirrorDownloadStrategy < CurlDownloadStrategy
|
||||||
def _fetch
|
def _fetch
|
||||||
# Fetch mirror list site
|
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
mirror_list = open(@url).read()
|
require 'vendor/multi_json'
|
||||||
|
|
||||||
# Parse out suggested mirror
|
mirrors = MultiJson.decode(open("#{@url}&asjson=1").read)
|
||||||
# Yep, this is ghetto, grep the first <strong></strong> element content
|
url = mirrors.fetch('preferred') + mirrors.fetch('path_info')
|
||||||
mirror_url = mirror_list[/<strong>([^<]+)/, 1]
|
|
||||||
|
|
||||||
raise "Couldn't determine mirror. Try again later." if mirror_url.nil?
|
ohai "Best Mirror #{url}"
|
||||||
|
curl url, '-o', @tarball_path
|
||||||
ohai "Best Mirror #{mirror_url}"
|
rescue IndexError
|
||||||
# Start download from that mirror
|
raise "Couldn't determine mirror. Try again later."
|
||||||
curl mirror_url, '-o', @tarball_path
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user