# File lib/smart_proxy_omaha/http_download.rb, line 13 def initialize(src, dst) @src = src @dst = dst @tmp = Tempfile.new('download', File.dirname(dst)) end
# File lib/smart_proxy_omaha/http_download.rb, line 57 def finish File.rename(tmp, dst) true end
# File lib/smart_proxy_omaha/http_download.rb, line 49 def join @task.join end
# File lib/smart_proxy_omaha/http_download.rb, line 27 def run logger.info "#{filename}: Downloading #{src} to #{dst}." unless download logger.error "#{filename} failed to download." return false end logger.info "#{filename}: Finished downloading #{dst}." unless valid? logger.error "#{filename} is not valid. Deleting corrupt file." File.unlink(tmp) return false end # no DIGESTS file is provided for update.gz # so we need to generate our own based on the # http headers write_digest if filename == 'update.gz' finish ensure tmp.unlink true end
# File lib/smart_proxy_omaha/http_download.rb, line 19 def start @task = Thread.new do @result = run end @task.abort_on_exception = true @task end
# File lib/smart_proxy_omaha/http_download.rb, line 53 def valid? verifier.valid? end
# File lib/smart_proxy_omaha/http_download.rb, line 62 def write_digest hexdigest = Digest.hexencode(Base64.decode64(verifier.local_md5)) File.open("#{dst}.DIGESTS", 'w') { |file| file.write("#{hexdigest} #{filename}\n") } end
# File lib/smart_proxy_omaha/http_download.rb, line 81 def download http, request = connection_factory(src) self.http_response = http.request(request) do |response| open(tmp, 'w') do |io| response.read_body do |chunk| io.write chunk end end end true end
# File lib/smart_proxy_omaha/http_download.rb, line 77 def filename File.basename(dst) end
# File lib/smart_proxy_omaha/http_download.rb, line 69 def verifier @verifier ||= HttpVerify.new( :local_file => tmp, :http_request => http_response, :filename => filename, ) end