Class: VagrantVbguest::Download
- Inherits:
-
Object
- Object
- VagrantVbguest::Download
- Defined in:
- lib/vagrant-vbguest/download.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#downloader ⇒ Object
readonly
Returns the value of attribute downloader.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #cleanup ⇒ Object
- #download! ⇒ Object
-
#initialize(source, destination, options = nil) ⇒ Download
constructor
A new instance of Download.
Constructor Details
#initialize(source, destination, options = nil) ⇒ Download
Returns a new instance of Download.
5 6 7 8 9 10 11 12 13 |
# File 'lib/vagrant-vbguest/download.rb', line 5 def initialize(source, destination, =nil) @downloader = nil @source = source @destination = destination if File.directory?(destination) @destination = File.join(destination, "vbguest_download_#{Time.now.to_i.to_s}") end @ui = [:ui] end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
3 4 5 |
# File 'lib/vagrant-vbguest/download.rb', line 3 def destination @destination end |
#downloader ⇒ Object (readonly)
Returns the value of attribute downloader.
3 4 5 |
# File 'lib/vagrant-vbguest/download.rb', line 3 def downloader @downloader end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
3 4 5 |
# File 'lib/vagrant-vbguest/download.rb', line 3 def source @source end |
Instance Method Details
#cleanup ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vagrant-vbguest/download.rb', line 23 def cleanup if destination && File.exist?(destination) @ui.info I18n.t("vagrant_vbguest.download.cleaning") # Unlinking the downloaded file might crash on Windows # see: https://github.com/dotless-de/vagrant-vbguest/issues/189 begin # Even if delete failed on Windows, we still can clean this file to save disk space File.open(destination,'wb') do |f| f.write('') f.close() end File.unlink(destination) rescue Errno::EACCES => e @ui.warn I18n.t("vagrant_vbguest.download.cleaning_failed", message: e., destination: destination) end end end |
#download! ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/vagrant-vbguest/download.rb', line 15 def download! = {} [:ui] = @ui @ui.info(I18n.t("vagrant_vbguest.download.started", :source => @source)) @downloader = Vagrant::Util::Downloader.new(@source, @destination, ) @downloader.download! end |