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
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
|