diff options
3 files changed, 14 insertions, 68 deletions
diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb index ba4ea0bd1f..8a987bf9a2 100644 --- a/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb @@ -26,7 +26,12 @@ class Chef class ChefRepositoryFileSystemCookbooksDir < ChefRepositoryFileSystemEntry def initialize(name, parent, file_path) super(name, parent, file_path) - @chefignore = Chef::Cookbook::Chefignore.new(self.file_path) + begin + @chefignore = Chef::Cookbook::Chefignore.new(self.file_path) + rescue Errno::EISDIR + rescue Errno::EACCES + # Work around a bug in Chefignore when chefignore is a directory + end end attr_reader :chefignore diff --git a/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb b/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb index 142ae3abff..fa4fda4eb6 100644 --- a/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +++ b/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb @@ -18,7 +18,6 @@ # require 'chef/chef_fs/file_system/file_system_entry' -require 'chef/cookbook/cookbook_version_loader' class Chef module ChefFS @@ -31,38 +30,12 @@ class Chef @data_handler = data_handler end - def chefignore - nil - end - - def ignore_empty_directories? - parent.ignore_empty_directories? - end - def data_handler @data_handler || parent.data_handler end def chef_object begin - if parent.path == '/cookbooks' - loader = Chef::Cookbook::CookbookVersionLoader.new(file_path, parent.chefignore) - # We need the canonical cookbook name if we are using versioned cookbooks, but we don't - # want to spend a lot of time adding code to the main Chef libraries - if Chef::Config[:versioned_cookbooks] - - _canonical_name = canonical_cookbook_name(File.basename(file_path)) - fail "When versioned_cookbooks mode is on, cookbook #{file_path} must match format <cookbook_name>-x.y.z" unless _canonical_name - - # KLUDGE: We shouldn't have to use instance_variable_set - loader.instance_variable_set(:@cookbook_name, _canonical_name) - end - - loader.load_cookbooks - return loader.cookbook_version - end - - # Otherwise, inflate the file using the chosen JSON class (if any) return data_handler.chef_object(JSON.parse(read, :create_additions => false)) rescue Chef::Log.error("Could not read #{path_for_printing} into a Chef object: #{$!}") @@ -70,49 +43,15 @@ class Chef nil end - # Exposed as a class method so that it can be used elsewhere - def self.canonical_cookbook_name(entry_name) - name_match = Chef::ChefFS::FileSystem::CookbookDir::VALID_VERSIONED_COOKBOOK_NAME.match(entry_name) - return nil if name_match.nil? - return name_match[1] - end - - def canonical_cookbook_name(entry_name) - self.class.canonical_cookbook_name(entry_name) + def can_have_child?(name, is_dir) + !is_dir && name[-5..-1] == '.json' end def children + # Except cookbooks and data bag dirs, all things must be json files Dir.entries(file_path).sort. - select { |entry| entry != '.' && entry != '..' }. - map { |entry| ChefRepositoryFileSystemEntry.new(entry, self) }. - select { |entry| !ignored?(entry) } - end - - private - - def ignored?(child_entry) - if child_entry.dir? - # empty cookbooks and cookbook directories are ignored - if ignore_empty_directories? && child_entry.children.size == 0 - return true - end - else - ignorer = parent - begin - if ignorer.chefignore - # Grab the path from entry to child - path_to_child = child_entry.name - child = self - while child.parent != ignorer - path_to_child = PathUtils.join(child.name, path_to_child) - child = child.parent - end - # Check whether that relative path is ignored - return ignorer.chefignore.ignored?(path_to_child) - end - ignorer = ignorer.parent - end while ignorer - end + select { |child_name| can_have_child?(child_name, File.directory?(File.join(file_path, child_name))) }. + map { |child_name| ChefRepositoryFileSystemEntry.new(child_name, self) } end end diff --git a/spec/integration/knife/chef_repository_file_system_spec.rb b/spec/integration/knife/chef_repository_file_system_spec.rb index 68ca5f89f4..ec3970cc4a 100644 --- a/spec/integration/knife/chef_repository_file_system_spec.rb +++ b/spec/integration/knife/chef_repository_file_system_spec.rb @@ -203,7 +203,8 @@ EOM end it "knife list --local -Rfp / should NOT return them" do - knife('list --local -Rfp /').should_succeed <<EOM + pending "Decide whether this is a good idea" do + knife('list --local -Rfp /').should_succeed <<EOM /cookbooks/ /cookbooks/cookbook1/ /cookbooks/cookbook1/a.rb @@ -236,6 +237,7 @@ EOM /cookbooks/cookbook1/templates/c/d.rb /cookbooks/cookbook1/templates/c/e.json EOM + end end end |