Method: Puppet::FileBucket::Dipper#backup

Defined in:
lib/vendor/puppet/file_bucket/dipper.rb

#backup(file) ⇒ Object

Back up a file to our bucket

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vendor/puppet/file_bucket/dipper.rb', line 33

def backup(file)
  raise(ArgumentError, "File #{file} does not exist") unless ::File.exist?(file)
  contents = IO.binread(file)
  begin
    file_bucket_file = Puppet::FileBucket::File.new(contents, :bucket_path => @local_path)
    files_original_path = absolutize_path(file)
    dest_path = "#{@rest_path}#{file_bucket_file.name}/#{files_original_path}"
    file_bucket_path = "#{@rest_path}#{file_bucket_file.checksum_type}/#{file_bucket_file.checksum_data}/#{files_original_path}"

    # Make a HEAD request for the file so that we don't waste time
    # uploading it if it already exists in the bucket.
    unless Puppet::FileBucket::File.indirection.head(file_bucket_path)
      Puppet::FileBucket::File.indirection.save(file_bucket_file, dest_path)
    end

    return file_bucket_file.checksum_data
  rescue => detail
    puts detail.backtrace if Puppet[:trace]
    raise Puppet::Error, "Could not back up #{file}: #{detail}"
  end
end