Class: Vagrant::Downloaders::File

Inherits:
Base
  • Object
show all
Defined in:
lib/vagrant/downloaders/file.rb

Overview

“Downloads” a file to a temporary file. Basically, this downloader simply does a file copy.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Vagrant::Downloaders::Base

Class Method Details

.match?(uri) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
# File 'lib/vagrant/downloaders/file.rb', line 9

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

Instance Method Details

#download!(source_url, destination_file) ⇒ Object



20
21
22
23
24
25
# File 'lib/vagrant/downloaders/file.rb', line 20

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