diff options
author | Tim Smith <tsmith@chef.io> | 2018-09-25 14:49:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-25 14:49:08 -0700 |
commit | ec31038f93cf6270cd79da12044a871b34dddf11 (patch) | |
tree | b03924b82b2ce142a40a9be17310b3f4135fe45a | |
parent | fd76e6c6b553c67fbbf2488ea0a5bddeb592c61c (diff) | |
parent | a60a1d9524e5ca5e878985dba940a9e2bbd5df72 (diff) | |
download | chef-ec31038f93cf6270cd79da12044a871b34dddf11.tar.gz |
Merge pull request #7687 from chef/dir_fix
Fix remote_directory does not obey removal of file specificity
-rw-r--r-- | lib/chef/cookbook_version.rb | 4 | ||||
-rw-r--r-- | spec/unit/cookbook_version_file_specificity_spec.rb | 30 |
2 files changed, 27 insertions, 7 deletions
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index dcb8c97548..6fcbc2912d 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -301,9 +301,9 @@ class Chef # we're just going to make cookbook_files out of these and make the # cookbook find them by filespecificity again. but it's the shortest # path to "success" for now. - if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)})\/.+$/ + if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]*\/?#{Regexp.escape(dirname)})\/.+$/ specificity_dirname = $1 - non_specific_path = manifest_record_path[/#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)}\/(.+)$/, 1] + non_specific_path = manifest_record_path[/#{Regexp.escape(segment.to_s)}\/[^\/]*\/?#{Regexp.escape(dirname)}\/(.+)$/, 1] # Record the specificity_dirname only if it's in the list of # valid preferences if filenames_by_pref[specificity_dirname] diff --git a/spec/unit/cookbook_version_file_specificity_spec.rb b/spec/unit/cookbook_version_file_specificity_spec.rb index ba7aaa59f5..de5f04695b 100644 --- a/spec/unit/cookbook_version_file_specificity_spec.rb +++ b/spec/unit/cookbook_version_file_specificity_spec.rb @@ -94,11 +94,18 @@ describe Chef::CookbookVersion, "file specificity" do # directory adirectory { - :name => "files/anotherfile1.rb", - :path => "files/host-examplehost.example.org/adirectory/anotherfile1.rb.host", - :full_path => "/cookbook-folder/files/host-examplehost.example.org/adirectory/anotherfile1.rb.host", - :checksum => "csum-host-1", - :specificity => "host-examplehost.example.org", + name: "files/anotherfile1.rb", + path: "files/root_directory/anotherfile1.rb.root", + checksum: "csum-root-directory", + specificity: "root_directory", + }, + + { + name: "files/anotherfile1.rb", + path: "files/host-examplehost.example.org/adirectory/anotherfile1.rb.host", + full_path: "/cookbook-folder/files/host-examplehost.example.org/adirectory/anotherfile1.rb.host", + checksum: "csum-host-1", + specificity: "host-examplehost.example.org", }, { :name => "files/anotherfile2.rb", @@ -483,6 +490,19 @@ describe Chef::CookbookVersion, "file specificity" do ## Globbing the relative paths out of the manifest records ## describe "when globbing for relative file paths based on filespecificity" do + it "should return a list of relative paths based on priority preference: root directory" do + node = Chef::Node.new + node.automatic_attrs[:platform] = "ubuntu" + node.automatic_attrs[:platform_version] = "9.10" + node.automatic_attrs[:fqdn] = "examplehost.example.org" + + filenames = @cookbook.relative_filenames_in_preferred_directory(node, :files, "root_directory") + expect(filenames).not_to be_nil + expect(filenames.size).to eq(1) + + expect(filenames.sort).to eq(["anotherfile1.rb.root"]) + end + it "should return a list of relative paths based on priority preference: host" do node = Chef::Node.new node.automatic_attrs[:platform] = "ubuntu" |