summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-09-05 21:21:25 -0700
committerJohn Keiser <john@johnkeiser.com>2015-08-07 14:19:31 -0700
commite0b89348187e107f3a7ccde775342f4845f833ba (patch)
tree0b382597f573b6e63340267f378fabf9c282d33a
parent4a3ede96a443a99748b2092e8c58d40ff8b2e104 (diff)
downloadchef-e0b89348187e107f3a7ccde775342f4845f833ba.tar.gz
Speed up file system access by not listing children on every
child(name) access. Also removes an intermittent warning when first downloading large numbers of cookbooks where sometimes a cookbook directory has been created but its children have not: when you run child('other_cookbook') it lists 'cookbooks'.children and notices the empty directory. Annoying, and probably affects knife-ec-backup.
-rw-r--r--lib/chef/chef_fs/file_system/file_system_entry.rb4
-rw-r--r--lib/chef/chef_fs/file_system/multiplexed_dir.rb17
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/chef/chef_fs/file_system/file_system_entry.rb b/lib/chef/chef_fs/file_system/file_system_entry.rb
index 1af7e618de..9bf5fc79b7 100644
--- a/lib/chef/chef_fs/file_system/file_system_entry.rb
+++ b/lib/chef/chef_fs/file_system/file_system_entry.rb
@@ -47,6 +47,10 @@ class Chef
end
end
+ def child(name)
+ make_child(name)
+ end
+
def create_child(child_name, file_contents=nil)
child = make_child(child_name)
if child.exists?
diff --git a/lib/chef/chef_fs/file_system/multiplexed_dir.rb b/lib/chef/chef_fs/file_system/multiplexed_dir.rb
index 06d4af705d..6c49f35cfd 100644
--- a/lib/chef/chef_fs/file_system/multiplexed_dir.rb
+++ b/lib/chef/chef_fs/file_system/multiplexed_dir.rb
@@ -24,7 +24,7 @@ class Chef
multiplexed_dirs.each do |dir|
dir.children.each do |child|
if seen[child.name]
- Chef::Log.warn("Child with name '#{child.name}' found in multiple directories: #{seen[child.name].path_for_printing} and #{child.path_for_printing}")
+ Chef::Log.warn("Child with name '#{child.name}' found in multiple directories: #{seen[child.name].path_for_printing} and #{dir.path_for_printing}")
else
result << child
seen[child.name] = child
@@ -35,6 +35,21 @@ class Chef
end
end
+ def child(name)
+ result = nil
+ multiplexed_dirs.each do |dir|
+ child_entry = dir.child(name)
+ if child_entry.exists?
+ if result
+ Chef::Log.warn("Child with name '#{child.name}' found in multiple directories: #{result.parent.path_for_printing} and #{child.parent.path_for_printing}")
+ else
+ result = child_entry
+ end
+ end
+ end
+ result || NonexistentFSObject.new(name, self)
+ end
+
def can_have_child?(name, is_dir)
write_dir.can_have_child?(name, is_dir)
end