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)
      found_pref = find_preferred_manifest_record(node, segment, 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 = if filename.is_a?(Array)
            filename.map{|name| "  #{File.join(segment.to_s, name)}"}
          else
            [
              "  #{segment}/#{node[:platform]}-#{node[:platform_version]}/#{filename}",
              "  #{segment}/#{node[:platform]}/#{filename}",
              "  #{segment}/default/#{filename}",
              "  #{segment}/#{filename}",
            ]
          end
          error_message << error_locations.join("\n")
          existing_files = segment_filenames(segment)
          existing_files.map!{|path| path[root_dir.length+1..-1]} if root_dir
          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 ) found_pref = find_preferred_manifest_record ( node , segment , 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 = if filename . is_a? ( Array ) filename . map { | name | "  #{File.join(segment.to_s, name)}" } else [ "  #{segment}/#{node[:platform]}-#{node[:platform_version]}/#{filename}" , "  #{segment}/#{node[:platform]}/#{filename}" , "  #{segment}/default/#{filename}" , "  #{segment}/#{filename}" , ] end error_message << error_locations . join ( "\n" ) existing_files = segment_filenames ( segment ) existing_files . map! { | path | path [ root_dir . length + 1 .. - 1 ] } if root_dir 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 .
# Strip the root_dir prefix off all files for readability # 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>