wip
This commit is contained in:
parent
7b746db64e
commit
44dd279f93
@ -1,3 +1,5 @@
|
||||
require "net/http"
|
||||
require "digest"
|
||||
require_relative "rscons/ansi"
|
||||
require_relative "rscons/application"
|
||||
require_relative "rscons/basic_environment"
|
||||
|
@ -37,6 +37,39 @@ module Rscons
|
||||
end.sort
|
||||
end
|
||||
|
||||
# Download a file.
|
||||
#
|
||||
# @param url [String]
|
||||
# URL.
|
||||
# @param dest [String]
|
||||
# Path to where to save the file.
|
||||
# @param options [Hash]
|
||||
# Options.
|
||||
# @option options [String] :sha256sum
|
||||
# Expected file checksum.
|
||||
#
|
||||
# @return [void]
|
||||
def download(url, dest, options = {})
|
||||
if File.exist?(dest) && options[:sha256sum]
|
||||
if Digest::SHA2.hexdigest(File.binread(dest)) == options[:sha256sum]
|
||||
# Destination file already exists and has the expected checksum.
|
||||
return
|
||||
end
|
||||
end
|
||||
uri = URI(url)
|
||||
http = Net::HTTP.new(uri.host)
|
||||
digest = Digest::SHA2.new
|
||||
File.open(dest, "wb") do |fh|
|
||||
http.get(uri.path) do |data|
|
||||
fh.write(data)
|
||||
digest << data
|
||||
end
|
||||
end
|
||||
if options[:sha256sum] && options[:sha256sum] != digest.hexdigest
|
||||
raise RsconsError.new("Unexpected checksum on #{dest}")
|
||||
end
|
||||
end
|
||||
|
||||
# Construct a task parameter.
|
||||
#
|
||||
# @param name [String]
|
||||
|
Loading…
x
Reference in New Issue
Block a user