Class: VagrantPlugins::ScpSync::Command::ScpSyncCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-scp-sync/command/scp.rb

Overview

This class defines SCPSync

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



12
13
14
# File 'lib/vagrant-scp-sync/command/scp.rb', line 12

def self.synopsis
  'Copies data into a box via SCP'
end

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/vagrant-scp-sync/command/scp.rb', line 16

def execute
  @source, @target = parse_args

  with_target_vms(host) do |machine|
    raise Vagrant::Errors::SSHNotReady if machine.ssh_info.nil?

    if @source.nil? && @target.nil?
      folders = machine.config.vm.synced_folders
      ssh_info = machine.ssh_info
      scp_path = Vagrant::Util::Which.which('scp')
      machine.ui.warn(I18n.t('vagrant.scp_ssh_password')) if ssh_info[:private_key_path].empty? && ssh_info[:password]
      folders.each_value do |folder_opts|
        next unless folder_opts[:type] == :scp

        VagrantPlugins::ScpSync::ScpSyncHelper.scp_single(machine, folder_opts, scp_path)
      end
    else
      ssh_info = machine.ssh_info
      scp_path = Vagrant::Util::Which.which('scp')
      direction = net_ssh_command(@source)
      source = format_file_path(machine, @source)
      target = format_file_path(machine, @target)
      folder_opts = {
        type: :scp,
        map: source,
        to: target,
        owner: ssh_info[:username],
        group: ssh_info[:username],
        direction: direction,
        scp__args: ['--delete'],
        rsync__args: ['--delete'],
        disabled: false,
        guestpath: target,
        hostpath: source
      }

      VagrantPlugins::ScpSync::ScpSyncHelper.scp_single(machine, folder_opts, scp_path)
    end
  end
end