15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/xcode/install.rb', line 15
def fetch(url, directory = nil, cookies = nil, output = nil, progress = true)
options = cookies.nil? ? [] : ['--cookie', cookies, '--cookie-jar', COOKIES_PATH]
uri = URI.parse(url)
output ||= File.basename(uri.path)
output = (Pathname.new(directory) + Pathname.new(output)) if directory
progress = progress ? '--progress-bar' : '--silent'
command = ['curl', *options, '--location', '--continue-at', '-', progress, '--output', output, url].map(&:to_s)
io = IO.popen(command)
io.each { |line| puts line }
io.close
result = $?.exitstatus == 0
FileUtils.rm_f(COOKIES_PATH)
result
end
|