summaryrefslogtreecommitdiff
path: root/lib/chef/cookbook
diff options
context:
space:
mode:
authorMal Graty <mal.graty@googlemail.com>2013-03-01 23:29:04 +0000
committerBryan McLellan <btm@opscode.com>2013-05-24 07:12:44 -0700
commit655444799b7acb90e40161684211352025d008f1 (patch)
treea4763032f8eb37461cd7db906660b61039d8f31d /lib/chef/cookbook
parent4079a344f2001c1927132e7ed6b63453f459609f (diff)
downloadchef-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')
-rw-r--r--lib/chef/cookbook/cookbook_version_loader.rb12
-rw-r--r--lib/chef/cookbook/file_system_file_vendor.rb8
-rw-r--r--lib/chef/cookbook/metadata.rb2
-rw-r--r--lib/chef/cookbook/syntax_check.rb8
4 files changed, 19 insertions, 11 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
diff --git a/lib/chef/cookbook/file_system_file_vendor.rb b/lib/chef/cookbook/file_system_file_vendor.rb
index 8896e3ed30..926e26e03d 100644
--- a/lib/chef/cookbook/file_system_file_vendor.rb
+++ b/lib/chef/cookbook/file_system_file_vendor.rb
@@ -41,10 +41,10 @@ class Chef
# Chef::Config.cookbook_path file hierarchy for the requested
# file.
def get_filename(filename)
- location = @repo_paths.inject(nil) do |memo, basepath|
- candidate_location = File.join(basepath, @cookbook_name, filename)
- memo = candidate_location if File.exist?(candidate_location)
- memo
+ cookbooks = Chef::CookbookLoader.new(@repo_paths).load_cookbooks
+ if cookbooks.has_key?(@cookbook_name)
+ location = File.join(cookbooks[@cookbook_name].root_dir, filename)
+ location = nil unless File.exist?(location)
end
raise "File #{filename} does not exist for cookbook #{@cookbook_name}" unless location
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index 18368bd99f..0cd740ea8f 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -91,7 +91,7 @@ class Chef
# metadata<Chef::Cookbook::Metadata>
def initialize(cookbook=nil, maintainer='YOUR_COMPANY_NAME', maintainer_email='YOUR_EMAIL', license='none')
@cookbook = cookbook
- @name = cookbook ? cookbook.name : ""
+ @name = cookbook ? cookbook.name : nil
@long_description = ""
self.maintainer(maintainer)
self.maintainer_email(maintainer_email)
diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb
index 40ba070796..09905bd9a6 100644
--- a/lib/chef/cookbook/syntax_check.rb
+++ b/lib/chef/cookbook/syntax_check.rb
@@ -84,14 +84,14 @@ class Chef
# validated.
attr_reader :validated_files
- # Creates a new SyntaxCheck given the +cookbook_name+ and a +cookbook_path+.
+ # Creates a new SyntaxCheck given the +cookbook_pathname+ and a +cookbook_path+.
# If no +cookbook_path+ is given, +Chef::Config.cookbook_path+ is used.
- def self.for_cookbook(cookbook_name, cookbook_path=nil)
+ def self.for_cookbook(cookbook_pathname, cookbook_path=nil)
cookbook_path ||= Chef::Config.cookbook_path
unless cookbook_path
- raise ArgumentError, "Cannot find cookbook #{cookbook_name} unless Chef::Config.cookbook_path is set or an explicit cookbook path is given"
+ raise ArgumentError, "Cannot find cookbook #{cookbook_pathname} unless Chef::Config.cookbook_path is set or an explicit cookbook path is given"
end
- new(File.join(cookbook_path, cookbook_name.to_s))
+ new(File.join(cookbook_path, cookbook_pathname.to_s))
end
# Create a new SyntaxCheck object