summaryrefslogtreecommitdiff
path: root/lib/chef/chef_fs
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-09-04 09:21:57 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-09-05 12:09:08 -0700
commitad0bfd815f24938acaf9d4627c31dee8a3642583 (patch)
treef10f537003e4ee1811c5c3e2130187917352fe99 /lib/chef/chef_fs
parentaef39bb741c3878bb8b5b2e50eeb909342e9933f (diff)
downloadchef-ad0bfd815f24938acaf9d4627c31dee8a3642583.tar.gz
Fix crash when repo root does not exist
Diffstat (limited to 'lib/chef/chef_fs')
-rw-r--r--lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb17
1 files changed, 10 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
#