Sha256: a5e3db1fee38e58a6a271097ecde7777df6d349753a25bca71dcd63887f649f8

Contents?: true

Size: 894 Bytes

Versions: 7

Compression:

Stored size: 894 Bytes

Contents

require 'fileutils'
require 'uri'

module Vagrant
  module Downloaders
    # "Downloads" a file to a temporary file. Basically, this downloader
    # simply does a file copy.
    class File < Base
      def self.match?(uri)
        extracted = URI.extract(uri, "file")

        # We match if we got a file URI. It doesn't matter here if the file
        # doesn't exist because we check again later as well.
        return true if extracted && extracted.include?(uri)

        # Otherwise we match if the file exists
        return ::File.file?(::File.expand_path(uri))
      end

      def download!(source_url, destination_file)
        raise Errors::DownloaderFileDoesntExist if !::File.file?(::File.expand_path(source_url))

        @ui.info I18n.t("vagrant.downloaders.file.download")
        FileUtils.cp(::File.expand_path(source_url), destination_file.path)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
vagrantup-1.1.3 lib/vagrant/downloaders/file.rb
vagrantup-1.1.2 lib/vagrant/downloaders/file.rb
vagrantup-1.1.1 lib/vagrant/downloaders/file.rb
vagrantup-1.1.0 lib/vagrant/downloaders/file.rb
vagrantup-1.1.4 lib/vagrant/downloaders/file.rb
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/lib/vagrant/downloaders/file.rb
vagrant-lxc-0.0.1 vendor/vagrant/lib/vagrant/downloaders/file.rb