class Kitchen::Transport::Sshtar::Connection

Public Instance Methods

upload(locals, remote) click to toggle source
# File lib/kitchen/transport/sshtar.rb, line 36
def upload(locals, remote)
  Array(locals).each do |local|
    recursive = File.directory?(local)
    if recursive
      full_remote = File.join(remote, File.basename(local))
      tar_command = "tar -C #{local} -c#{@logger.debug? ? 'v' : ''}f - ./"
      untar_command = "tar #{@logger.debug? ? '' : '--warning=none'} -C #{full_remote} -x#{@logger.debug? ? 'v' : ''}f -"
      execute("mkdir -p #{full_remote}") if recursive
    else
      local_dir = File.dirname(local)
      local_file = File.basename(local)
      full_remote = remote
      tar_command = "tar -C #{local_dir} -c#{@logger.debug? ? 'v' : ''}f - #{local_file}"
      untar_command = "tar #{@logger.debug? ? '' : '--warning=none'} -C #{full_remote} -x#{@logger.debug? ? 'v' : ''}f - #{local_file}"
    end
    time = Benchmark.realtime do
      ssh_command = [login_command.command, login_command.arguments].flatten.join(' ')
      sync_command = "#{tar_command} | #{ssh_command} '#{untar_command}'"
      @logger.debug("[SSH-TAR] Running ssh-tar command: #{sync_command}")
      system(sync_command)
    end
    logger.info("[SSH-TAR] Time taken to upload #{local} to #{self}:#{full_remote}: %.2f sec" % time)
  end
end