summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-05-28 09:11:58 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-06-07 13:12:35 -0700
commit603db5ec5f54ee8c435b097ef0fa336e0e9f3dc0 (patch)
tree59cd7bceb8948d965d8dd78352724184b10d0904 /lib/chef
parent9958e628ebbfd569d6a2f5a2d714020e3783a959 (diff)
downloadchef-603db5ec5f54ee8c435b097ef0fa336e0e9f3dc0.tar.gz
Support listing missing top-level directories in knife serve
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/chef_fs/file_system/memory_dir.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/chef/chef_fs/file_system/memory_dir.rb b/lib/chef/chef_fs/file_system/memory_dir.rb
index c0ae1a2027..91a4c7aa64 100644
--- a/lib/chef/chef_fs/file_system/memory_dir.rb
+++ b/lib/chef/chef_fs/file_system/memory_dir.rb
@@ -27,14 +27,24 @@ class Chef
def add_file(path, value)
path_parts = path.split('/')
- if path_parts.length == 1
- add_child(MemoryFile.new(path_parts[0], self, value))
- else
- if !child(path_parts[0]).exists?
- add_child(MemoryDir.new(path_parts[0], self))
+ dir = add_dir(path_parts[0..-2].join('/'))
+ file = MemoryFile.new(path_parts[0], dir, value)
+ dir.add_child(file)
+ file
+ end
+
+ def add_dir(path)
+ path_parts = path.split('/')
+ dir = self
+ path_parts.each do |path_part|
+ subdir = dir.child(path_part)
+ if !subdir.exists?
+ subdir = MemoryDir.new(path_part, dir)
+ dir.add_child(subdir)
end
- child(path_parts[0]).add_file(path_parts[1..-1], value)
+ dir = subdir
end
+ dir
end
end
end