diff options
author | John Keiser <john@johnkeiser.com> | 2016-08-17 09:52:34 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2016-08-17 10:45:26 -0700 |
commit | 9efaeeb3fae794c97045c15a33dacb0c771eb11a (patch) | |
tree | c0f865f05ecf07e4d1b1b0fe1d35db3773dd3337 /lib | |
parent | 87d719302a245d266a43d4445dc9d0cd11d93e20 (diff) | |
download | chef-9efaeeb3fae794c97045c15a33dacb0c771eb11a.tar.gz |
Fix symlink tests on Ruby 2.3 on Windows
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/cookbook/cookbook_version_loader.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index 56fe3838d9..af8b2e043e 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -225,17 +225,29 @@ class Chef # assumed to be managed by chef-zero and not part of the cookbook. def load_all_files return unless File.exist?(cookbook_path) - # The trailing / tells find to traverse the top level symlink - Find.find("#{cookbook_path}/") do |path| - relative_path = Chef::Util::PathHelper.relative_path_from(@cookbook_path, path) - path = Pathname.new(path).cleanpath.to_s + # If cookbook_path is a symlink, Find on Windows Ruby 2.3 will not traverse it. + # Dir.entries will do so on all platforms, so we iterate the top level using + # Dir.entries. Since we have different behavior at the top anyway (hidden + # directories at the top level are not included for backcompat), this + # actually keeps things a bit cleaner. + Dir.entries(cookbook_path).each do |top_filename| # Skip top-level directories starting with "." - if File.directory?(path) && relative_path.to_s.start_with?(".") && relative_path.to_s != "." - Find.prune - - # Add files to the list of files - elsif File.file?(path) && File.basename(relative_path) != UPLOADED_COOKBOOK_VERSION_FILE + top_path = File.join(cookbook_path, top_filename) + next if File.directory?(top_path) && top_filename.start_with?(".") + + # Use Find.find because it: + # (a) returns any children, recursively + # (b) includes top_path as well + # (c) skips symlinks, which is backcompat (no judgement on whether it was *right*) + Find.find(top_path) do |path| + # Only add files, not directories + next unless File.file?(path) + # Don't add .uploaded-cookbook-version.json + next if File.basename(path) == UPLOADED_COOKBOOK_VERSION_FILE + + relative_path = Chef::Util::PathHelper.relative_path_from(cookbook_path, path) + path = Pathname.new(path).cleanpath.to_s cookbook_settings[:all_files][relative_path] = path end end |