Sha256: 132ea4ef224cb4f7df668b00980b3c08cc11d171f191153a1ef39bca390f3f94

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

module VagrantVbguest

  class DownloadBase
    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!
      raise NotImplementedError
    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

11 entries across 11 versions & 1 rubygems

Version Path
vagrant-vbguest-0.16.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.16.0.beta1 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.15.2 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.15.1 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.15.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.14.2 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.14.1 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.14.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.14.0.pre.beta1 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.13.0 lib/vagrant-vbguest/download.rb
vagrant-vbguest-0.12.0 lib/vagrant-vbguest/download.rb