mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-09 15:37:56 -05:00
downloader.rb: add file:// protocol support, fallback to curl when the protocol is not http(s):///file:// (#6520)
* Update downloader.rb * Update const.rb
This commit is contained in:
@@ -21,6 +21,28 @@ def downloader (url, filename = File.basename(url), retry_count = 0, verbose = f
|
||||
trap('WINCH') { setTermSize }
|
||||
uri = URI(url)
|
||||
|
||||
case uri.scheme
|
||||
when /http?/
|
||||
when 'file'
|
||||
# use FileUtils to copy if it is a local file (the url protocol is file://)
|
||||
if File.exist?(uri.path)
|
||||
return FileUtils.cp uri.path, filename
|
||||
else
|
||||
abort "#{uri.path}: File not found :/".lightred
|
||||
end
|
||||
else
|
||||
# fallback to curl if the url protocol is not http(s):// or file://
|
||||
0.step(3,1) do |i|
|
||||
unless system "#{CURL} --ssl -#L -C - '#{uri.to_s}' -o '#{filename}'"
|
||||
puts "Retrying, #{3-i} retries left.".yellow
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
# the download failed if we're still here
|
||||
abort 'Download failed :/ Please check your network settings.'.lightred
|
||||
end
|
||||
|
||||
Net::HTTP.start(uri.host, uri.port, {
|
||||
max_retries: 3,
|
||||
use_ssl: uri.scheme.eql?('https'),
|
||||
|
||||
Reference in New Issue
Block a user