lib/vagrant/util/downloader.rb in vagrant-unbundled-2.0.2.0 vs lib/vagrant/util/downloader.rb in vagrant-unbundled-2.0.3.0
- old
+ new
@@ -23,10 +23,16 @@
CHECKSUM_MAP = {
:md5 => Digest::MD5,
:sha1 => Digest::SHA1
}.freeze
+ # Hosts that do not require notification on redirect
+ SILENCED_HOSTS = [
+ "vagrantcloud.com".freeze,
+ "vagrantup.com".freeze
+ ].freeze
+
attr_reader :source
attr_reader :destination
def initialize(source, destination, options=nil)
options ||= {}
@@ -81,11 +87,11 @@
# If we're outputting progress, then setup the subprocess to
# tell us output so we can parse it out.
extra_subprocess_opts[:notify] = :stderr
progress_data = ""
- progress_regexp = /(\r(.+?))\r/
+ progress_regexp = /^\r\s*(\d.+?)\r/m
# Setup the proc that'll receive the real-time data from
# the downloader.
data_proc = Proc.new do |type, data|
# Type will always be "stderr" because that is the only
@@ -93,17 +99,49 @@
# Accumulate progress_data
progress_data << data
while true
+ # If the download has been redirected and we are no longer downloading
+ # from the original host, notify the user that the target host has
+ # changed from the source.
+ if progress_data.include?("Location")
+ location = progress_data.scan(/Location: (.+?)$/m).flatten.compact.first.to_s.strip
+ if !location.empty?
+ @logger.info("download redirected to #{location}")
+ location_uri = URI.parse(location)
+ source_uri = URI.parse(source)
+ source_host = source_uri.host.split(".", 2).last
+ location_host = location_uri.host.split(".", 2).last
+ if !@redirect_notify && location_host != source_host && !SILENCED_HOSTS.include?(location_host)
+ @ui.clear_line
+ @ui.detail "Download redirected to host: #{location_uri.host}"
+ end
+ @redirect_notify = true
+ end
+ progress_data.replace("")
+ break
+ end
+
# If we have a full amount of column data (two "\r") then
# we report new progress reports. Otherwise, just keep
# accumulating.
- match = progress_regexp.match(progress_data)
+ match = nil
+ check_match = true
+
+ while check_match
+ check_match = progress_regexp.match(progress_data)
+ if check_match
+ data = check_match[1].to_s
+ stop = progress_data.index(data) + data.length
+ progress_data.slice!(0, stop)
+
+ match = check_match
+ end
+ end
+
break if !match
- data = match[2]
- progress_data.gsub!(match[1], "")
# Ignore the first \r and split by whitespace to grab the columns
columns = data.strip.split(/\s+/)
# COLUMN DATA:
@@ -271,10 +309,10 @@
# Build the list of parameters to execute with cURL
options = [
"-q",
"--fail",
"--location",
- "--max-redirs", "10",
+ "--max-redirs", "10", "--verbose",
"--user-agent", USER_AGENT,
]
options += ["--cacert", @ca_cert] if @ca_cert
options += ["--capath", @ca_path] if @ca_path