summaryrefslogtreecommitdiff
path: root/lib/chef
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2013-06-12 20:13:14 -0700
committerJohn Keiser <jkeiser@opscode.com>2013-09-12 23:04:20 -0700
commitdb8992f649b88dd5a9cbb772ee3de5845ceb8b90 (patch)
treed2b44e6c287fde90d88ecf926b2f3ea8ed52f967 /lib/chef
parentc0e7a53d0a4db2b8c45b506359e0bdab3ee4638c (diff)
downloadchef-db8992f649b88dd5a9cbb772ee3de5845ceb8b90.tar.gz
Don't report random files in json dirs (like roles/environments)
Diffstat (limited to 'lib/chef')
-rw-r--r--lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb7
-rw-r--r--lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb71
2 files changed, 11 insertions, 67 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