summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2016-02-26 16:52:06 -0800
committerdanielsdeleo <dan@chef.io>2016-02-26 17:42:30 -0800
commitd5e17c6459f9aebc032b2be85266900e3d23e423 (patch)
tree585d44d6450217a9c46af31062490b9f60542ff4
parente4f0839f18ddfaea1519b65dbcdd759dd9988c4e (diff)
downloadchef-d5e17c6459f9aebc032b2be85266900e3d23e423.tar.gz
Load root files as a part of all_files
-rw-r--r--lib/chef/cookbook/cookbook_version_loader.rb37
1 files changed, 25 insertions, 12 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb
index 0e3fb2ef72..b19aac270d 100644
--- a/lib/chef/cookbook/cookbook_version_loader.rb
+++ b/lib/chef/cookbook/cookbook_version_loader.rb
@@ -224,26 +224,39 @@ class Chef
@chefignore ||= Chefignore.new(File.basename(cookbook_path))
end
+ # Enumerate all the files in a cookbook and assign the resulting list to
+ # `cookbook_settings[:all_files]`. In order to behave in a compatible way
+ # with previous implementations, directories at the cookbook's root that
+ # begin with a dot are ignored. dotfiles are generally not ignored,
+ # however if the file is named ".uploaded-cookbook-version.json" it is
+ # assumed to be managed by chef-zero and not part of the cookbook.
def load_all_files
- # List all directories that are not dotdirs, then list everything in
- # those, *including* dotfiles and dotdirs.
- # Finally, list all the _files_ at the root, including dotfiles, and
- # merge those in.
- Dir.glob(File.join(Chef::Util::PathHelper.escape_glob(cookbook_path), "*")).each do |dir|
- dir = Chef::Util::PathHelper.cleanpath(dir)
- next unless File.directory?(dir)
-
- Dir.glob(File.join(Chef::Util::PathHelper.escape_glob(dir), "**/*"), File::FNM_DOTMATCH).each do |file|
+ Dir.glob(File.join(Chef::Util::PathHelper.escape_glob(cookbook_path), "*"), File::FNM_DOTMATCH).each do |fs_entry|
+ if File.directory?(fs_entry)
+ dir_relpath = Chef::Util::PathHelper.relative_path_from(@cookbook_path, fs_entry)
+
+ next if dir_relpath.to_s.start_with?(".")
+
+ Dir.glob(File.join(fs_entry, "**/*"), File::FNM_DOTMATCH).each do |file|
+ file = Chef::Util::PathHelper.cleanpath(file)
+ name = Chef::Util::PathHelper.relative_path_from(@cookbook_path, file)
+ cookbook_settings[:all_files][name] = file
+ end
+ elsif File.file?(fs_entry)
+ file = Chef::Util::PathHelper.cleanpath(fs_entry)
+
+ next if File.basename(file) == UPLOADED_COOKBOOK_VERSION_FILE
+
name = Chef::Util::PathHelper.relative_path_from(@cookbook_path, file)
cookbook_settings[:all_files][name] = file
+ else # pipes, devices, other weirdness
+ next
end
end
- load_root_files
- cookbook_settings[:all_files].merge!(cookbook_settings[:root_filenames])
end
def load_root_files
- Dir.glob(File.join(Chef::Util::PathHelper.escape_glob(cookbook_path), "*"), File::FNM_DOTMATCH).each do |file|
+ select_files_by_glob(File.join(Chef::Util::PathHelper.escape_glob(cookbook_path), "*"), File::FNM_DOTMATCH).each do |file|
file = Chef::Util::PathHelper.cleanpath(file)
next if File.directory?(file)
next if File.basename(file) == UPLOADED_COOKBOOK_VERSION_FILE