diff options
author | Mal Graty <mal.graty@googlemail.com> | 2013-03-01 23:29:04 +0000 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-05-24 07:12:44 -0700 |
commit | 655444799b7acb90e40161684211352025d008f1 (patch) | |
tree | a4763032f8eb37461cd7db906660b61039d8f31d /lib/chef/cookbook/cookbook_version_loader.rb | |
parent | 4079a344f2001c1927132e7ed6b63453f459609f (diff) | |
download | chef-655444799b7acb90e40161684211352025d008f1.tar.gz |
Fixes CHEF-3307
Use metadata name when loading cookbook
If a name attribute is loaded from a cookbooks metadata, use this for
dependency checks and references as specified in documentation. Ensure real
pathname is retained so that manifests can still be generated correctly.
In addition we must read the metadata implicitly when cookbooks are loaded to
ensure we are using the correct name.
Also include a deprecation warning when encountering missing names in metadata
as this is a planned breaking change in Chef 12.
Diffstat (limited to 'lib/chef/cookbook/cookbook_version_loader.rb')
-rw-r--r-- | lib/chef/cookbook/cookbook_version_loader.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index e98da77d7f..a990489ff6 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -18,13 +18,15 @@ class Chef :provider_filenames] + attr_reader :cookbook_pathname attr_reader :cookbook_name attr_reader :cookbook_settings attr_reader :metadata_filenames def initialize(path, chefignore=nil) @cookbook_path = File.expand_path( path ) - @cookbook_name = File.basename( path ) + @cookbook_pathname = File.basename( path ) + @cookbook_name = @cookbook_pathname @chefignore = chefignore @metadata = Hash.new @relative_path = /#{Regexp.escape(@cookbook_path)}\/(.+)$/ @@ -64,14 +66,18 @@ class Chef if empty? Chef::Log.warn "found a directory #{cookbook_name} in the cookbook path, but it contains no cookbook files. skipping." + else + metadata = @metadata.is_a?(Metadata) ? @metadata : metadata(nil) + @cookbook_name = metadata.name.to_sym unless metadata.name.nil? end + @cookbook_settings end def cookbook_version return nil if empty? - Chef::CookbookVersion.new(@cookbook_name.to_sym).tap do |c| + Chef::CookbookVersion.new(@cookbook_pathname.to_sym).tap do |c| c.root_dir = @cookbook_path c.attribute_filenames = cookbook_settings[:attribute_filenames].values c.definition_filenames = cookbook_settings[:definition_filenames].values @@ -84,6 +90,7 @@ class Chef c.root_filenames = cookbook_settings[:root_filenames].values c.metadata_filenames = @metadata_filenames c.metadata = metadata(c) + c.name = c.metadata.name.to_sym end end @@ -100,6 +107,7 @@ class Chef raise RuntimeError, "Invalid metadata file: #{metadata_file} for cookbook: #{cookbook_version}" end end + Chef::Log.warn "Inferred cookbook names are deprecated, please set a name in metadata" unless @metadata.name @metadata end |