summaryrefslogtreecommitdiff
path: root/lib/chef/cookbook_version.rb
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-10-10 15:17:47 -0700
committerSerdar Sutay <serdar@opscode.com>2014-10-10 15:17:47 -0700
commit0b44df383395482d96e317babf0546068c30b7ec (patch)
treec02a47d217f8fb96fc282afaa5b3e0699d4d5e7d /lib/chef/cookbook_version.rb
parent6a9aab14f1b6ee3c654ec947ef4484aa3a507dbc (diff)
parente6291e1af8e923f3af4c5ea864e815d27c53d4aa (diff)
downloadchef-0b44df383395482d96e317babf0546068c30b7ec.tar.gz
Merge pull request #2165 from coderanger/rfc017
RFC 17 implementation
Diffstat (limited to 'lib/chef/cookbook_version.rb')
-rw-r--r--lib/chef/cookbook_version.rb83
1 files changed, 51 insertions, 32 deletions
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 95af94bdf7..505b403e65 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -315,13 +315,20 @@ class Chef
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_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)
+ # Strip the root_dir prefix off all files for readability
+ existing_files.map!{|path| path[root_dir.length+1..-1]} if root_dir
# Show the files that the cookbook does have. If the user made a typo,
# hopefully they'll see it here.
unless existing_files.empty?
@@ -421,38 +428,44 @@ class Chef
def preferences_for_path(node, segment, path)
# only files and templates can be platform-specific
if segment.to_sym == :files || segment.to_sym == :templates
- begin
- platform, version = Chef::Platform.find_platform_and_version(node)
- rescue ArgumentError => e
- # Skip platform/version if they were not found by find_platform_and_version
- if e.message =~ /Cannot find a (?:platform|version)/
- platform = "/unknown_platform/"
- version = "/unknown_platform_version/"
- else
- raise
+ relative_search_path = if path.is_a?(Array)
+ path
+ else
+ begin
+ platform, version = Chef::Platform.find_platform_and_version(node)
+ rescue ArgumentError => e
+ # Skip platform/version if they were not found by find_platform_and_version
+ if e.message =~ /Cannot find a (?:platform|version)/
+ platform = "/unknown_platform/"
+ version = "/unknown_platform_version/"
+ else
+ raise
+ end
end
- end
- fqdn = node[:fqdn]
+ fqdn = node[:fqdn]
- # Break version into components, eg: "5.7.1" => [ "5.7.1", "5.7", "5" ]
- search_versions = []
- parts = version.to_s.split('.')
+ # Break version into components, eg: "5.7.1" => [ "5.7.1", "5.7", "5" ]
+ search_versions = []
+ parts = version.to_s.split('.')
- parts.size.times do
- search_versions << parts.join('.')
- parts.pop
- end
+ parts.size.times do
+ search_versions << parts.join('.')
+ parts.pop
+ end
- # Most specific to least specific places to find the path
- 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)
+ # Most specific to least specific places to find the path
+ search_path = [ File.join("host-#{fqdn}", path) ]
+ search_versions.each do |v|
+ search_path << File.join("#{platform}-#{v}", path)
+ end
+ search_path << File.join(platform.to_s, path)
+ search_path << File.join("default", path)
+ search_path << path
- search_path
+ search_path
+ end
+ relative_search_path.map {|relative_path| File.join(segment.to_s, relative_path)}
else
[File.join(segment, path)]
end
@@ -666,7 +679,13 @@ class Chef
# Check if path is actually under root_path
next if parts[0] == '..'
if segment == :templates || segment == :files
- return [ pathname.to_s, parts[1] ]
+ # Check if pathname looks like files/foo or templates/foo (unscoped)
+ if pathname.each_filename.to_a.length == 2
+ # Use root_default in case the same path exists at root_default and default
+ return [ pathname.to_s, 'root_default' ]
+ else
+ return [ pathname.to_s, parts[1] ]
+ end
else
return [ pathname.to_s, 'default' ]
end