diff options
author | John Keiser <john@johnkeiser.com> | 2016-08-16 16:37:50 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2016-08-16 17:22:02 -0700 |
commit | 438cd46c773fb752556d1ed61e49ad0a359fc059 (patch) | |
tree | 7b6e44632f379d0e08a9f8be0438b71b0c9005c6 | |
parent | 51581a0d11ddfac8db97712c6c3c680910db706c (diff) | |
download | chef-jk/windows-ruby-2.3.tar.gz |
Don't use relative_path_from on glob resultsjk/windows-ruby-2.3
Windows Ruby 2.3 translates pathnames like ADMINI~1 to Administrator, making the comparison fail.
-rw-r--r-- | lib/chef/cookbook/cookbook_version_loader.rb | 35 | ||||
-rw-r--r-- | spec/integration/knife/chef_repo_path_spec.rb | 71 |
2 files changed, 84 insertions, 22 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index d9b027f322..5683ca7de7 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -3,6 +3,7 @@ require "chef/cookbook_version" require "chef/cookbook/chefignore" require "chef/cookbook/metadata" require "chef/util/path_helper" +require "find" class Chef class Cookbook @@ -223,27 +224,19 @@ class Chef # 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 - Dir.glob(File.join(Chef::Util::PathHelper.escape_glob_dir(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| - next if File.directory?(file) - file = Pathname.new(file).cleanpath.to_s - name = Chef::Util::PathHelper.relative_path_from(@cookbook_path, file) - cookbook_settings[:all_files][name] = file - end - elsif File.file?(fs_entry) - file = Pathname.new(fs_entry).cleanpath.to_s - - 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 + 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 + + # 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 + cookbook_settings[:all_files][relative_path] = path end end end diff --git a/spec/integration/knife/chef_repo_path_spec.rb b/spec/integration/knife/chef_repo_path_spec.rb index cf12b7ddfe..1388aa8716 100644 --- a/spec/integration/knife/chef_repo_path_spec.rb +++ b/spec/integration/knife/chef_repo_path_spec.rb @@ -48,7 +48,7 @@ describe "chef_repo_path tests", :workstation do directory "chef_repo2" do file "clients/client3.json", {} - file "cookbooks/cookbook3/metadata.rb", "" + file "cookbooks/cookbook3/metadata.rb", "name 'cookbook3'" file "data_bags/bag3/item3.json", {} file "environments/env3.json", {} file "nodes/node3.json", {} @@ -79,6 +79,75 @@ describe "chef_repo_path tests", :workstation do EOM end + it "knife list --local -Rfp --chef-repo-path chef_r~1 / grabs chef_repo2 stuff", :windows_only do + Chef::Config.delete(:chef_repo_path) + knife("list --local -Rfp --chef-repo-path #{path_to('chef_r~1')} /").should_succeed <<EOM +/clients/ +/clients/client3.json +/cookbooks/ +/cookbooks/cookbook3/ +/cookbooks/cookbook3/metadata.rb +/data_bags/ +/data_bags/bag3/ +/data_bags/bag3/item3.json +/environments/ +/environments/env3.json +/nodes/ +/nodes/node3.json +/roles/ +/roles/role3.json +/users/ +/users/user3.json +EOM + end + + it "knife list --local -Rfp --chef-repo-path chef_r~1 / grabs chef_repo2 stuff", :windows_only do + Chef::Config.delete(:chef_repo_path) + knife("list -z -Rfp --chef-repo-path #{path_to('chef_r~1')} /").should_succeed <<EOM +/acls/ +/acls/clients/ +/acls/clients/client3.json +/acls/containers/ +/acls/cookbook_artifacts/ +/acls/cookbooks/ +/acls/cookbooks/cookbook3.json +/acls/data_bags/ +/acls/data_bags/bag3.json +/acls/environments/ +/acls/environments/env3.json +/acls/groups/ +/acls/nodes/ +/acls/nodes/node3.json +/acls/organization.json +/acls/policies/ +/acls/policy_groups/ +/acls/roles/ +/acls/roles/role3.json +/clients/ +/clients/client3.json +/containers/ +/cookbook_artifacts/ +/cookbooks/ +/cookbooks/cookbook3/ +/cookbooks/cookbook3/metadata.rb +/data_bags/ +/data_bags/bag3/ +/data_bags/bag3/item3.json +/environments/ +/environments/env3.json +/groups/ +/invitations.json +/members.json +/nodes/ +/nodes/node3.json +/org.json +/policies/ +/policy_groups/ +/roles/ +/roles/role3.json +EOM + end + context "when all _paths are set to alternates" do before :each do %w{client cookbook data_bag environment node role user}.each do |object_name| |