summaryrefslogtreecommitdiff
path: root/lib/chef/cookbook
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2017-04-25 11:17:53 +0100
committerThom May <thom@chef.io>2017-04-25 11:17:53 +0100
commite31b32ac7f8a6eddde22cd0fd915e7302447bdb3 (patch)
treeda8bb7453bb4bb621de884943649b00eb44e1591 /lib/chef/cookbook
parentc7aa5baef1621b5ccd8dd240befe71e34b84f931 (diff)
downloadchef-e31b32ac7f8a6eddde22cd0fd915e7302447bdb3.tar.gz
lazily load cookbook_files and templatestm/even_lazier
Fixes: #6051 Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib/chef/cookbook')
-rw-r--r--lib/chef/cookbook/remote_file_vendor.rb2
-rw-r--r--lib/chef/cookbook/synchronizer.rb27
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/chef/cookbook/remote_file_vendor.rb b/lib/chef/cookbook/remote_file_vendor.rb
index cfd7789311..668d74c9ce 100644
--- a/lib/chef/cookbook/remote_file_vendor.rb
+++ b/lib/chef/cookbook/remote_file_vendor.rb
@@ -62,7 +62,7 @@ class Chef
# If the checksums are different between on-disk (current) and on-server
# (remote, per manifest), do the update. This will also execute if there
# is no current checksum.
- if current_checksum != found_manifest_record["checksum"]
+ if found_manifest_record[:lazy] || current_checksum != found_manifest_record["checksum"]
raw_file = @rest.streaming_request(found_manifest_record[:url])
Chef::Log.debug("Storing updated #{cache_filename} in the cache.")
diff --git a/lib/chef/cookbook/synchronizer.rb b/lib/chef/cookbook/synchronizer.rb
index 625f3b4f20..ed6b1d9700 100644
--- a/lib/chef/cookbook/synchronizer.rb
+++ b/lib/chef/cookbook/synchronizer.rb
@@ -71,6 +71,8 @@ class Chef
@cookbook_full_file_paths = {}
@remove_obsoleted_files = true
+
+ @lazy_files = {}
end
def cache
@@ -98,15 +100,22 @@ class Chef
end
def files
- exclude = unless Chef::Config[:no_lazy_load]
- [ :files, :templates ]
- else
- []
- end
+ lazy = unless Chef::Config[:no_lazy_load]
+ %w{ files templates }
+ else
+ []
+ end
@files ||= cookbooks.inject([]) do |memo, cookbook|
- cookbook.each_file(excluded_parts: exclude) do |manifest_record|
- memo << CookbookFile.new(cookbook, manifest_record)
+ cookbook.each_file do |manifest_record|
+ part = manifest_record[:name].split("/")[0]
+ if lazy.include?(part)
+ manifest_record[:lazy] = true
+ @lazy_files[cookbook] ||= []
+ @lazy_files[cookbook] << manifest_record
+ else
+ memo << CookbookFile.new(cookbook, manifest_record)
+ end
end
memo
end
@@ -230,6 +239,10 @@ class Chef
@cookbook_full_file_paths.each do |cookbook, full_paths|
cookbook.all_files = full_paths
end
+
+ @lazy_files.each do |cookbook, lazy_files|
+ cookbook.cookbook_manifest.add_files_to_manifest(lazy_files)
+ end
end
def ensure_cookbook_paths