chef/lib/chef/cookbook_version.rb
# Given a node, segment and path (filename or directory name),
# return the priority-ordered list of preference locations to
# look.
Given a node, segment and path (filename or directory name),
return the priority-ordered list of preference locations to
look.
Given a node segment and path ( filename or directory name ) return the priority - ordered list of preference locations to look .
def preferences_for_path(node, segment, path)
      if segment.to_sym == :files || segment.to_sym == :templates
        begin
          platform, version = Chef::Platform.find_platform_and_version(node)
        rescue ArgumentError => e
          if e.message =~ /Cannot find a (?:platform|version)/
            platform = "/unknown_platform/"
            version = "/unknown_platform_version/"
          else
            raise
          end
        end
        fqdn = node[:fqdn]
        search_versions = []
        parts = version.to_s.split('.')
        parts.size.times do
          search_versions << parts.join('.')
          parts.pop
        end
        search_path = [ File.join(segment.to_s, "host-#{fqdn}", path) ]
        search_versions.each do |v|
          search_path << File.join(segment.to_s, "#{platform}-#{v}", path)
        end
        search_path << File.join(segment.to_s, platform.to_s, path)
        search_path << File.join(segment.to_s, "default", path)
        search_path
      else
        [File.join(segment, path)]
      end
    end
def preferences_for_path ( node , segment , path ) if segment . to_sym == :files || segment . to_sym == :templates begin platform , version = Chef :: Platform . find_platform_and_version ( node ) rescue ArgumentError => e if e . message =~ / Cannot find a (?:platform|version) / platform = "/unknown_platform/" version = "/unknown_platform_version/" else raise end end fqdn = node [ :fqdn ] search_versions = [ ] parts = version . to_s . split ( '.' ) parts . size . times do search_versions << parts . join ( '.' ) parts . pop end search_path = [ File . join ( segment . to_s , "host-#{fqdn}" , path ) ] search_versions . each do | v | search_path << File . join ( segment . to_s , "#{platform}-#{v}" , path ) end search_path << File . join ( segment . to_s , platform . to_s , path ) search_path << File . join ( segment . to_s , "default" , path ) search_path else [ File . join ( segment , path ) ] end end
Given a node, segment and path (filename or directory name),
return the priority-ordered list of preference locations to
look.
Given a node segment and path ( filename or directory name ) return the priority - ordered list of preference locations to look .
# only files and templates can be platform-specific # Skip platform/version if they were not found by find_platform_and_version # Break version into components, eg: "5.7.1" => [ "5.7.1", "5.7", "5" ] # Most specific to least specific places to find the path
node
<not_specific>
segment
<not_specific>
path
<not_specific>