Class: VagrantVbguest::DownloadBase

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vbguest/download.rb

Direct Known Subclasses

Download

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, destination, options = nil) ⇒ DownloadBase

Returns a new instance of DownloadBase.



6
7
8
9
10
11
12
13
14
# File 'lib/vagrant-vbguest/download.rb', line 6

def initialize(source, destination, options=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 = options[:ui]
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination.



4
5
6
# File 'lib/vagrant-vbguest/download.rb', line 4

def destination
  @destination
end

#downloaderObject (readonly)

Returns the value of attribute downloader.



4
5
6
# File 'lib/vagrant-vbguest/download.rb', line 4

def downloader
  @downloader
end

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/vagrant-vbguest/download.rb', line 4

def source
  @source
end

Instance Method Details

#cleanupObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/vagrant-vbguest/download.rb', line 20

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.message, destination: destination)
    end
  end
end

#download!Object

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/vagrant-vbguest/download.rb', line 16

def download!
  raise NotImplementedError
end