diff options
author | Ryota Arai <ryota.arai@gmail.com> | 2013-11-07 22:31:21 +0900 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-11-26 07:31:26 -0800 |
commit | 0ead522ef5a257327c230b6bd3036523a80de70e (patch) | |
tree | b783dbcc23f8d33fd1fe2f2f785a5d082a2e0e5b | |
parent | 0d04ea2672e0ec5d492e5640fe3fd94a64e47554 (diff) | |
download | chef-0ead522ef5a257327c230b6bd3036523a80de70e.tar.gz |
Raise an error if any directory of `cookbook_path` contains no cookbook.
-rw-r--r-- | lib/chef/client.rb | 15 | ||||
-rw-r--r-- | spec/unit/client_spec.rb | 2 |
2 files changed, 7 insertions, 10 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 38b771147e..a8387f4e9d 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -543,8 +543,8 @@ class Chef end end - def directory_not_empty?(path) - File.exists?(path) && (Dir.entries(path).size > 2) + def empty_directory?(path) + !File.exists?(path) || (Dir.entries(path).size <= 2) end def is_last_element?(index, object) @@ -556,13 +556,10 @@ class Chef # Check for cookbooks in the path given # Chef::Config[:cookbook_path] can be a string or an array # if it's an array, go through it and check each one, raise error at the last one if no files are found - Chef::Log.debug "Loading from cookbook_path: #{Array(Chef::Config[:cookbook_path]).map { |path| File.expand_path(path) }.join(', ')}" - empty_cookbook_paths = [] - Array(Chef::Config[:cookbook_path]).each do |cookbook_path| - empty_cookbook_paths << cookbook_path unless directory_not_empty?(cookbook_path) - end - unless empty_cookbook_paths.empty? - msg = "No cookbook found in #{empty_cookbook_paths.inspect}, make sure cookbook_path is set correctly." + cookbook_paths = Array(Chef::Config[:cookbook_path]) + Chef::Log.debug "Loading from cookbook_path: #{cookbook_paths.map { |path| File.expand_path(path) }.join(', ')}" + if cookbook_paths.all? {|path| empty_directory?(path) } + msg = "None of the cookbook paths, #{cookbook_paths.inspect}, contain any cookbooks" Chef::Log.fatal(msg) raise Chef::Exceptions::CookbookNotFound, msg end diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 67b6623402..6a87e217e5 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -456,7 +456,7 @@ shared_examples_for Chef::Client do it "raises CookbookNotFound error" do expect do @client.send(:assert_cookbook_path_not_empty, nil) - end.to raise_error(Chef::Exceptions::CookbookNotFound, 'No cookbook found in ["/path/to/invalid/cookbook_path"], make sure cookbook_path is set correctly.') + end.to raise_error(Chef::Exceptions::CookbookNotFound, 'None of the cookbook paths, ["/path/to/invalid/cookbook_path"], contain any cookbooks') end end end |