summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-05-11 11:47:23 +0100
committerGitHub <noreply@github.com>2017-05-11 11:47:23 +0100
commit9d948676a6647283ef73f233dcbd98a6aff00c00 (patch)
treef15377c57a67d1a6c222e0b39d3918ae4f10fe3d
parent9e4d838680cd7bf436a16396c6779e38dc415182 (diff)
parentc7dd04cf25bfa9c4740fb36222e9e82c41038fee (diff)
downloadchef-9d948676a6647283ef73f233dcbd98a6aff00c00.tar.gz
Merge pull request #6129 from akitada/nil-segments
Discard caches for files not in the manifest
-rw-r--r--lib/chef/cookbook/synchronizer.rb2
-rw-r--r--spec/unit/cookbook/synchronizer_spec.rb12
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb
index bb44bc3d5c..e243d19151 100644
--- a/lib/chef/cookbook/synchronizer.rb
+++ b/lib/chef/cookbook/synchronizer.rb
@@ -202,7 +202,7 @@ class Chef
( cookbook_name, segment, file ) = md[1..3]
if have_cookbook?(cookbook_name)
manifest_segment = cookbook_segment(cookbook_name, segment)
- if manifest_segment.select { |manifest_record| manifest_record["path"] == "#{segment}/#{file}" }.empty?
+ if manifest_segment.nil? || manifest_segment.select { |manifest_record| manifest_record["path"] == "#{segment}/#{file}" }.empty?
Chef::Log.info("Removing #{cache_file} from the cache; its is no longer in the cookbook manifest.")
cache.delete(cache_file)
@events.removed_cookbook_file(cache_file)
diff --git a/spec/unit/cookbook/synchronizer_spec.rb b/spec/unit/cookbook/synchronizer_spec.rb
index 82876273e7..d652ce4063 100644
--- a/spec/unit/cookbook/synchronizer_spec.rb
+++ b/spec/unit/cookbook/synchronizer_spec.rb
@@ -191,6 +191,18 @@ describe Chef::CookbookSynchronizer do
allow(synchronizer).to receive(:cache).and_return(file_cache)
synchronizer.remove_deleted_files
end
+
+ it "removes files not in the manifest" do
+ not_in_manifest_cb_file = %w{cookbooks/valid1/test/deleted.rb cookbooks/valid1/spec/deleted.rb}
+ expect(file_cache).to receive(:find).with(File.join(%w{cookbooks ** {*,.*}})).and_return(not_in_manifest_cb_file)
+ expect(synchronizer).to receive(:have_cookbook?).with("valid1").at_least(:once).and_return(true)
+ expect(file_cache).to receive(:delete).with("cookbooks/valid1/test/deleted.rb")
+ expect(file_cache).to receive(:delete).with("cookbooks/valid1/spec/deleted.rb")
+ expect(synchronizer).to receive(:cookbook_segment).with("valid1", "test").at_least(:once).and_return(nil)
+ expect(synchronizer).to receive(:cookbook_segment).with("valid1", "spec").at_least(:once).and_return(nil)
+ allow(synchronizer).to receive(:cache).and_return(file_cache)
+ synchronizer.remove_deleted_files
+ end
end
let(:cookbook_a_default_recipe_tempfile) do