From ad0bfd815f24938acaf9d4627c31dee8a3642583 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Thu, 4 Sep 2014 09:21:57 -0700 Subject: Fix crash when repo root does not exist --- .../file_system/chef_repository_file_system_root_dir.rb | 17 ++++++++++------- spec/integration/knife/list_spec.rb | 6 ++++++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb index 1e180a8f57..fde8e23fa8 100644 --- a/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb @@ -49,7 +49,7 @@ class Chef # - root_paths - an array of paths representing the top level, where # org.json, members.json, and invites.json will be stored. # - def initialize(child_paths, root_paths=nil) + def initialize(child_paths, root_paths=[]) super("", nil) @child_paths = child_paths @root_paths = root_paths @@ -73,7 +73,7 @@ class Chef def can_have_child?(name, is_dir) if is_dir child_paths.has_key?(name) - elsif root_paths + elsif root_dir CHILDREN.include?(name) else false @@ -124,11 +124,14 @@ class Chef # members.json and org.json may be found. # def root_dir - MultiplexedDir.new(root_paths.select { |path| File.exists?(path) }.map do |path| - dir = ChefRepositoryFileSystemEntry.new(name, parent, path) - dir.write_pretty_json = !!write_pretty_json - dir - end) + existing_paths = root_paths.select { |path| File.exists?(path) } + if existing_paths.size > 0 + MultiplexedDir.new(existing_paths.map do |path| + dir = ChefRepositoryFileSystemEntry.new(name, parent, path) + dir.write_pretty_json = !!write_pretty_json + dir + end) + end end # diff --git a/spec/integration/knife/list_spec.rb b/spec/integration/knife/list_spec.rb index 48e85f43bb..c9632e146d 100644 --- a/spec/integration/knife/list_spec.rb +++ b/spec/integration/knife/list_spec.rb @@ -661,7 +661,10 @@ EOM /data_bags /environments /groups +/invitations.json +/members.json /nodes +/org.json /roles EOM end @@ -676,7 +679,10 @@ cookbooks data_bags environments groups +invitations.json +members.json nodes +org.json roles /acls: -- cgit v1.2.1