Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Forked from imbriaco/gist:101375
Created April 27, 2009 04:20
Show Gist options
  • Save jtimberman/102325 to your computer and use it in GitHub Desktop.
Save jtimberman/102325 to your computer and use it in GitHub Desktop.
diff --git a/chef-server-slice/app/controllers/application.rb b/chef-server-slice/app/controllers/application.rb
index de03021..7978809 100644
--- a/chef-server-slice/app/controllers/application.rb
+++ b/chef-server-slice/app/controllers/application.rb
@@ -22,6 +22,8 @@ require "chef" / "cookbook_loader"
class ChefServerSlice::Application < Merb::Controller
+ include Chef::Mixin::Checksum
+
controller_for_slice
# Generate the absolute url for a slice - takes the slice's :path_prefix into account.
@@ -168,7 +170,8 @@ class ChefServerSlice::Application < Merb::Controller
file_name = mo[1]
files << {
:cookbook => cookbook.name,
- :name => file_name
+ :name => file_name,
+ :checksum => checksum(sf)
}
end
end
diff --git a/chef/lib/chef/client.rb b/chef/lib/chef/client.rb
index 44b26bf..766811f 100644
--- a/chef/lib/chef/client.rb
+++ b/chef/lib/chef/client.rb
@@ -241,22 +241,24 @@ class Chef
current_checksum ? { 'checksum' => current_checksum } : nil
)
Chef::Log.debug(rf_url)
-
- changed = true
- begin
- raw_file = @rest.get_rest(rf_url, true)
- rescue Net::HTTPRetriableError => e
- if e.response.kind_of?(Net::HTTPNotModified)
- changed = false
- Chef::Log.debug("Cache file #{cache_file} is unchanged")
- else
- raise e
+
+ if current_checksum != rf['checksum']
+ changed = true
+ begin
+ raw_file = @rest.get_rest(rf_url, true)
+ rescue Net::HTTPRetriableError => e
+ if e.response.kind_of?(Net::HTTPNotModified)
+ changed = false
+ Chef::Log.debug("Cache file #{cache_file} is unchanged")
+ else
+ raise e
+ end
+ end
+
+ if changed
+ Chef::Log.info("Storing updated #{cache_file} in the cache.")
+ Chef::FileCache.move_to(raw_file.path, cache_file)
end
- end
-
- if changed
- Chef::Log.info("Storing updated #{cache_file} in the cache.")
- Chef::FileCache.move_to(raw_file.path, cache_file)
end
end
@@ -309,7 +311,7 @@ class Chef
# === Returns
# true:: Always returns true
def sync_recipes
- Chef::Log.debug("Synchronizing recipes")
+ Chef::Log.debug("Synchronizing recipes")
update_file_cache("recipes", @rest.get_rest('cookbooks/_recipe_files'))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment