Sha256: 49cd61be88bc16aa1559d653b2cccdf842d128b002c8e0f25d9edad557d503cf

Contents?: true

Size: 1.35 KB

Versions: 22

Compression:

Stored size: 1.35 KB

Contents

module VagrantVbguest
  class Download
    attr_reader :source, :destination, :downloader

    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

    def download!
      downloader_options = {}
      downloader_options[:ui] = @ui
      @ui.info(I18n.t("vagrant_vbguest.download.started", :source => @source))
      @downloader = Vagrant::Util::Downloader.new(@source, @destination, downloader_options)
      @downloader.download!
    end

    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
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
vagrant-vbguest-0.32.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.31.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.30.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.29.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.28.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.27.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.26.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.25.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.24.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.24.0.beta1 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.23.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.22.1 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.22.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.21.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.20.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.19.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.18.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.17.2 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.17.1 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.17.0 lib/vagrant-vbguest/download.rb