Method: Bolt::Transport::LXD::Connection#upload_file

Defined in:
lib/bolt/transport/lxd/connection.rb

#upload_file(source, destination) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/bolt/transport/lxd/connection.rb', line 72

def upload_file(source, destination)
  @logger.trace { "Uploading #{source} to #{destination}" }
  args = %w[--create-dirs]
  if File.directory?(source)
    args << '--recursive'
    # If we don't do this, LXD will upload to
    # /tmp/d2020-11/d2020-11/dir instead of /tmp/d2020-11/dir
    destination = Pathname.new(destination).dirname.to_s
  end
  cmd = %w[file push] + args + %W[#{source} #{container_id}#{destination}]
  _out, err, stat = execute_local_command(cmd)
  unless stat.exitstatus.zero?
    raise "Error writing to #{container_id}: #{err}"
  end
rescue StandardError => e
  raise Bolt::Node::FileError.new(e.message, 'WRITE_ERROR')
end