Method: Puppet::FileBucketFile::File#find

Defined in:
lib/puppet/indirector/file_bucket_file/file.rb

#find(request) ⇒ Object



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
# File 'lib/puppet/indirector/file_bucket_file/file.rb', line 16

def find(request)
  request.options[:bucket_path] ||= Puppet[:bucketdir]
  # If filebucket mode is 'list'
  if request.options[:list_all]
    return nil unless ::File.exist?(request.options[:bucket_path])

    return list(request)
  end
  checksum, files_original_path = request_to_checksum_and_path(request)
  contents_file = path_for(request.options[:bucket_path], checksum, 'contents')
  paths_file = path_for(request.options[:bucket_path], checksum, 'paths')

  if Puppet::FileSystem.exist?(contents_file) && matches(paths_file, files_original_path)
    if request.options[:diff_with]
      other_contents_file = path_for(request.options[:bucket_path], request.options[:diff_with], 'contents')
      raise _("could not find diff_with %{diff}") % { diff: request.options[:diff_with] } unless Puppet::FileSystem.exist?(other_contents_file)
      raise _("Unable to diff on this platform") unless Puppet[:diff] != ""

      diff(Puppet::FileSystem.path_string(contents_file), Puppet::FileSystem.path_string(other_contents_file))
    else
      # TRANSLATORS "FileBucket" should not be translated
      Puppet.info _("FileBucket read %{checksum}") % { checksum: checksum }
      model.new(Puppet::FileSystem.binread(contents_file))
    end
  else
    nil
  end
end