lib/chef/cookbook_version.rb
# Determine the most specific manifest record for the given
# segment/filename, given information in the node. Throws
# FileNotFound if there is no such segment and filename in the
# manifest.
#
# A manifest record is a Mash that follows the following form:
# {
#   :name => "example.rb",
#   :path => "files/default/example.rb",
#   :specificity => "default",
#   :checksum => "1234"
# }
Determine the most specific manifest record for the given
segment/filename, given information in the node. Throws
FileNotFound if there is no such segment and filename in the
manifest.


Determine the most specific manifest record for the given segment / filename given information in the node . Throws FileNotFound if there is no such segment and filename in the manifest .
def preferred_manifest_record(node, segment, filename)
      preferences = preferences_for_path(node, segment, filename)
      manifest
      found_pref = preferences.find {|preferred_filename| @manifest_records_by_path[preferred_filename] }
      if found_pref
        @manifest_records_by_path[found_pref]
      else
        if segment == :files || segment == :templates
          error_message = "Cookbook '#{name}' (#{version}) does not contain a file at any of these locations:\n"
          error_locations = [
            "  #{segment}/#{node[:platform]}-#{node[:platform_version]}/#{filename}",
            "  #{segment}/#{node[:platform]}/#{filename}",
            "  #{segment}/default/#{filename}",
          ]
          error_message << error_locations.join("\n")
          existing_files = segment_filenames(segment)
          unless existing_files.empty?
            error_message << "\n\nThis cookbook _does_ contain: ['#{existing_files.join("','")}']"
          end
          raise Chef::Exceptions::FileNotFound, error_message
        else
          raise Chef::Exceptions::FileNotFound, "cookbook #{name} does not contain file #{segment}/#{filename}"
        end
      end
    end
def preferred_manifest_record ( node , segment , filename ) preferences = preferences_for_path ( node , segment , filename ) manifest found_pref = preferences . find { | preferred_filename | @manifest_records_by_path [ preferred_filename ] } if found_pref @manifest_records_by_path [ found_pref ] else if segment == :files || segment == :templates error_message = "Cookbook '#{name}' (#{version}) does not contain a file at any of these locations:\n" error_locations = [ "  #{segment}/#{node[:platform]}-#{node[:platform_version]}/#{filename}" , "  #{segment}/#{node[:platform]}/#{filename}" , "  #{segment}/default/#{filename}" , ] error_message << error_locations . join ( "\n" ) existing_files = segment_filenames ( segment ) unless existing_files . empty? error_message << "\n\nThis cookbook _does_ contain: ['#{existing_files.join("','")}']" end raise Chef :: Exceptions :: FileNotFound , error_message else raise Chef :: Exceptions :: FileNotFound , "cookbook #{name} does not contain file #{segment}/#{filename}" end end end
Determine the most specific manifest record for the given
segment/filename, given information in the node.
Determine the most specific manifest record for the given segment / filename given information in the node .
# ensure that we generate the manifest, which will also generate # @manifest_records_by_path # in order of prefernce, look for the filename in the manifest # Show the files that the cookbook does have. If the user made a typo, # hopefully they'll see it here.
node
<not_specific>
segment
<not_specific>
filename
<not_specific>