Class: Proxy::Omaha::HttpDownload
- Inherits:
-
Object
- Object
- Proxy::Omaha::HttpDownload
- Includes:
- Log, HttpShared
- Defined in:
- lib/smart_proxy_omaha/http_download.rb
Instance Attribute Summary collapse
-
#dst ⇒ Object
Returns the value of attribute dst.
-
#http_response ⇒ Object
Returns the value of attribute http_response.
-
#result ⇒ Object
Returns the value of attribute result.
-
#src ⇒ Object
Returns the value of attribute src.
-
#tmp ⇒ Object
Returns the value of attribute tmp.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(src, dst) ⇒ HttpDownload
constructor
A new instance of HttpDownload.
- #join ⇒ Object
- #run ⇒ Object
- #start ⇒ Object
- #valid? ⇒ Boolean
- #write_digest ⇒ Object
Methods included from HttpShared
Constructor Details
#initialize(src, dst) ⇒ HttpDownload
Returns a new instance of HttpDownload.
13 14 15 16 17 |
# 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 |
Instance Attribute Details
#dst ⇒ Object
Returns the value of attribute dst.
11 12 13 |
# File 'lib/smart_proxy_omaha/http_download.rb', line 11 def dst @dst end |
#http_response ⇒ Object
Returns the value of attribute http_response.
11 12 13 |
# File 'lib/smart_proxy_omaha/http_download.rb', line 11 def http_response @http_response end |
#result ⇒ Object
Returns the value of attribute result.
11 12 13 |
# File 'lib/smart_proxy_omaha/http_download.rb', line 11 def result @result end |
#src ⇒ Object
Returns the value of attribute src.
11 12 13 |
# File 'lib/smart_proxy_omaha/http_download.rb', line 11 def src @src end |
#tmp ⇒ Object
Returns the value of attribute tmp.
11 12 13 |
# File 'lib/smart_proxy_omaha/http_download.rb', line 11 def tmp @tmp end |
Instance Method Details
#finish ⇒ Object
57 58 59 60 |
# File 'lib/smart_proxy_omaha/http_download.rb', line 57 def finish File.rename(tmp, dst) true end |
#join ⇒ Object
49 50 51 |
# File 'lib/smart_proxy_omaha/http_download.rb', line 49 def join @task.join end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |
#start ⇒ Object
19 20 21 22 23 24 25 |
# 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 |
#valid? ⇒ Boolean
53 54 55 |
# File 'lib/smart_proxy_omaha/http_download.rb', line 53 def valid? verifier.valid? end |
#write_digest ⇒ Object
62 63 64 65 |
# 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 |