Properly accumulate and parse cURL output for progress
This commit is contained in:
parent
05c6379abb
commit
d1e2596ce5
|
@ -42,15 +42,26 @@ module Vagrant
|
|||
# tell us output so we can parse it out.
|
||||
options << { :notify => :stderr }
|
||||
|
||||
progress_data = ""
|
||||
progress_regexp = /(\r(.+?))\r/
|
||||
|
||||
# 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
|
||||
# type of data we're subscribed for notifications.
|
||||
|
||||
# If the data doesn't start with a \r then it isn't a progress
|
||||
# notification, so ignore it.
|
||||
next if data[0] != "\r"
|
||||
# Accumulate progress_data
|
||||
progress_data << data
|
||||
|
||||
while true
|
||||
# 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)
|
||||
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[1..-1].split(/\s+/)
|
||||
|
@ -76,6 +87,7 @@ module Vagrant
|
|||
@ui.info(output, :new_line => false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Create the callback that is called if we are interrupted
|
||||
interrupted = false
|
||||
|
|
Loading…
Reference in New Issue