Class: VagrantPlugins::VagrantWinRM::WinRMUpload

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-winrm/commands/winrm_upload.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



6
7
8
# File 'lib/vagrant-winrm/commands/winrm_upload.rb', line 6

def self.synopsis
  'upload file or directory to machine via WinRM'
end

Instance Method Details

#executeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-winrm/commands/winrm_upload.rb', line 10

def execute
  options = { temporary: false, compress: false }
  source, destination, argv = parse_args options

  return unless source || destination

  # Execute the actual WinRM
  with_target_vms(argv, single_target: true) do |vm|

    raise Errors::ConfigurationError, { :communicator => vm.config.vm.communicator } if vm.config.vm.communicator != :winrm

    tmp_dest = get_remote_temp_folder(vm) if options[:temporary] || options[:compress]

    dest_file = options[:temporary] ? ::File.join(tmp_dest, destination) : destination
    $stdout.print dest_file if options[:temporary]

    @logger.debug("Uploading #{source} to #{destination}")
    if options[:compress]
      source_is_dir = ::File.directory? source
      source = compress(source, source_is_dir)

      dest_dir = source_is_dir || dest_file.end_with?('/') || dest_file.end_with?('\\') ? dest_file : ::File.dirname(dest_file)
      remote_tgz_path = ::File.join(::File.dirname(tmp_dest), ::File.basename(source))
      vm.communicate.upload(source, remote_tgz_path)
      return vm.communicate.execute("New-Item '#{dest_dir}' -type directory -force; tar -xzf '#{remote_tgz_path}' -C '#{dest_dir}'; ")
    else
      return vm.communicate.upload(source, dest_file)
    end
  end
end