lib/chef/cookbook_version.rb in chef-0.10.4 vs lib/chef/cookbook_version.rb in chef-0.10.6.beta.1
- old
+ new
@@ -628,11 +628,28 @@
# in order of prefernce, look for the filename in the manifest
found_pref = preferences.find {|preferred_filename| @manifest_records_by_path[preferred_filename] }
if found_pref
@manifest_records_by_path[found_pref]
else
- raise Chef::Exceptions::FileNotFound, "cookbook #{name} does not contain file #{segment}/#{filename}"
+ 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)
+ # Show the files that the cookbook does have. If the user made a typo,
+ # hopefully they'll see it here.
+ 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_filename_on_disk_location(node, segment, filename, current_filepath=nil)
manifest_record = preferred_manifest_record(node, segment, filename)
@@ -673,11 +690,11 @@
end
end
best_pref = preferences.find { |pref| !filenames_by_pref[pref].empty? }
- raise Chef::Exceptions::FileNotFound, "cookbook #{name} has no directory #{segment}/#{dirname}" unless best_pref
+ raise Chef::Exceptions::FileNotFound, "cookbook #{name} has no directory #{segment}/default/#{dirname}" unless best_pref
filenames_by_pref[best_pref]
end
@@ -708,11 +725,11 @@
end
end
best_pref = preferences.find { |pref| !records_by_pref[pref].empty? }
- raise Chef::Exceptions::FileNotFound, "cookbook #{name} has no directory #{segment}/#{dirname}" unless best_pref
+ raise Chef::Exceptions::FileNotFound, "cookbook #{name} (#{version}) has no directory #{segment}/default/#{dirname}" unless best_pref
records_by_pref[best_pref]
end
@@ -734,16 +751,27 @@
end
end
fqdn = node[:fqdn]
+ # 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
+
# Most specific to least specific places to find the path
- [
- File.join(segment.to_s, "host-#{fqdn}", path),
- File.join(segment.to_s, "#{platform}-#{version}", path),
- File.join(segment.to_s, platform.to_s, path),
- File.join(segment.to_s, "default", 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)
+
+ search_path
else
[File.join(segment, path)]
end
end
private :preferences_for_path