    # File lib/chef/cookbook_version.rb, line 708
        def preferred_manifest_records_for_directory(node, segment, dirname)
          preferences = preferences_for_path(node, segment, dirname)
          records_by_pref = Hash.new
          preferences.each { |pref| records_by_pref[pref] = Array.new }

          manifest[segment].each do |manifest_record|
            manifest_record_path = manifest_record[:path]

            # extract the preference part from the path.
            if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)})\/.+$/
              # Note the specificy_dirname includes the segment and
              # dirname argument as above, which is what
              # preferences_for_path returns. It could be
              # "files/ubuntu-9.10/dirname", for example.
              specificity_dirname = $1

              # Record the specificity_dirname only if it's in the list of
              # valid preferences
              if records_by_pref[specificity_dirname]
                records_by_pref[specificity_dirname] << manifest_record
              end
            end
          end

          best_pref = preferences.find { |pref| !records_by_pref[pref].empty? }

          raise Chef::Exceptions::FileNotFound, "cookbook #{name} (#{version}) has no directory #{segment}/default/#{dirname}" unless best_pref

          records_by_pref[best_pref]
        end