Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'CHEF-2308'

  • Loading branch information...
commit f1b7f2e965670fd3e50e035fc509972fedb4d1e5 2 parents 2de8e35 + 5a9fee8
@danielsdeleo danielsdeleo authored
View
18 chef/lib/chef/cookbook_loader.rb
@@ -30,6 +30,8 @@ class CookbookLoader
attr_accessor :metadata
attr_reader :cookbooks_by_name
+ attr_reader :merged_cookbooks
+ attr_reader :cookbook_paths
include Enumerable
@@ -39,9 +41,23 @@ def initialize(*repo_paths)
@cookbooks_by_name = Mash.new
@loaded_cookbooks = {}
@metadata = Mash.new
+ @cookbooks_paths = Hash.new {|h,k| h[k] = []} # for deprecation warnings
+
+ # Used to track which cookbooks appear in multiple places in the cookbook repos
+ # and are merged in to a single cookbook by file shadowing. This behavior is
+ # deprecated, so users of this class may issue warnings to the user by checking
+ # this variable
+ @merged_cookbooks = []
+
load_cookbooks
end
+ def merged_cookbook_paths # for deprecation warnings
+ merged_cookbook_paths = {}
+ @merged_cookbooks.each {|c| merged_cookbook_paths[c] = @cookbooks_paths[c]}
+ merged_cookbook_paths
+ end
+
def load_cookbooks
cookbook_settings = Hash.new
@repo_paths.each do |repo_path|
@@ -52,7 +68,9 @@ def load_cookbooks
loader = Cookbook::CookbookVersionLoader.new(cookbook_path, chefignore)
loader.load_cookbooks
next if loader.empty?
+ @cookbooks_paths[loader.cookbook_name] << cookbook_path # for deprecation warnings
if @loaded_cookbooks.key?(loader.cookbook_name)
+ @merged_cookbooks << loader.cookbook_name # for deprecation warnings
@loaded_cookbooks[loader.cookbook_name].merge!(loader)
else
@loaded_cookbooks[loader.cookbook_name] = loader
View
17 chef/lib/chef/knife/cookbook_upload.rb
@@ -65,6 +65,7 @@ def run
config[:cookbook_path] ||= Chef::Config[:cookbook_path]
assert_environment_valid!
+ warn_about_cookbook_shadowing
version_constraints_to_update = {}
if config[:all]
@@ -117,6 +118,22 @@ def environment
@environment ||= config[:environment] ? Environment.load(config[:environment]) : nil
end
+ def warn_about_cookbook_shadowing
+ unless cookbook_repo.merged_cookbooks.empty?
+ ui.warn "* " * 40
+ ui.warn(<<-WARNING)
+The cookbooks: #{cookbook_repo.merged_cookbooks.join(', ')} exist in multiple places in your cookbook_path.
+A composite version of these cookbooks has been compiled for uploading.
+
+#{ui.color('IMPORTANT:', :red, :bold)} In a future version of Chef, this behavior will be removed and you will no longer
+be able to have the same version of a cookbook in multiple places in your cookbook_path.
+WARNING
+ ui.warn "The affected cookbooks are located:"
+ ui.output ui.format_for_display(cookbook_repo.merged_cookbook_paths)
+ ui.warn "* " * 40
+ end
+ end
+
private
def assert_environment_valid!
Please sign in to comment.
Something went wrong with that request. Please try again.