Class: Vagrant::Util::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/util/uploader.rb

Overview

This class uploads files using various protocols by subprocessing to cURL. cURL is a much more capable and complete download tool than a hand-rolled Ruby library, so we defer to its expertise.

Instance Method Summary collapse

Constructor Details

#initialize(destination, file, options = nil) ⇒ Uploader

Returns a new instance of Uploader.

Parameters:

  • destination (String)
    • valid URL to upload file to
  • file (String)
    • location of file to upload on disk
  • options (Hash) (defaults to: nil)


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vagrant/util/uploader.rb', line 19

def initialize(destination, file, options=nil)
  options ||= {}
  @logger         = Log4r::Logger.new("vagrant::util::uploader")
  @destination    = destination.to_s
  @file           = file.to_s
  @ui             = options[:ui]
  @request_method = options[:method]

  if !@request_method
    @request_method = "PUT"
  end
end

Instance Method Details

#upload!Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrant/util/uploader.rb', line 32

def upload!
  data_proc = Vagrant::Util::CurlHelper.capture_output_proc(@logger, @ui)

  @logger.info("Uploader starting upload: ")
  @logger.info("  -- Source: #{@file}")
  @logger.info("  -- Destination: #{@destination}")

  options = build_options
  subprocess_options = {notify: :stderr}

  begin
    execute_curl(options, subprocess_options, &data_proc)
  rescue Errors::UploaderError => e
    raise
  ensure
    @ui.clear_line if @ui
  end
end