diff options
author | Ben Somers <somers.ben@gmail.com> | 2013-05-16 13:53:34 -0700 |
---|---|---|
committer | Ben Somers <somers.ben@gmail.com> | 2014-06-08 16:35:40 -0700 |
commit | a93af4060369f23299652b92fdc451468a3e5534 (patch) | |
tree | e36cf4fb083a15669041fafd5a0492251478affd /lib/chef/role.rb | |
parent | fb8375f99b6cf192484049383a9349416873e1fa (diff) | |
download | chef-a93af4060369f23299652b92fdc451468a3e5534.tar.gz |
Added duplicate role detection for Role.from_disk
Now Role.from_disk raises an error when it detects two roles
of the same type (.rb or .json) exist anywhere in the roles directory
or subdirectories.
Diffstat (limited to 'lib/chef/role.rb')
-rw-r--r-- | lib/chef/role.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/chef/role.rb b/lib/chef/role.rb index 6f2c6318fc..26bf574737 100644 --- a/lib/chef/role.rb +++ b/lib/chef/role.rb @@ -236,8 +236,12 @@ class Chef paths = Array(Chef::Config[:role_path]) paths.each do |path| roles_files = Dir.glob(File.join(path, "**", "**")) - js_path = roles_files.detect { |file| file.match /#{name}\.json$/ } - rb_path = roles_files.detect { |file| file.match /#{name}\.rb$/ } + js_files = roles_files.select { |file| file.match /#{name}\.json$/ } + rb_files = roles_files.select { |file| file.match /#{name}\.rb$/ } + if js_files.count > 1 or rb_files.count > 1 + raise Chef::Exceptions::DuplicateRole, "Multiple roles of same type found named #{name}" + end + js_path, rb_path = js_files.first, rb_files.first if js_path && (File.exists?(js_path) || force == "json") # from_json returns object.class => json_class in the JSON. |