Permalink
Browse files

[CHEF-3715] remove caching of sha256 cksums

This also eliminates the dependency on moneta.
  • Loading branch information...
1 parent 6bdcab7 commit 2c460c191bcdb1acfe6978a6e7e7ff8e0273f973 @danielsdeleo danielsdeleo committed Dec 21, 2012
View
@@ -26,9 +26,8 @@ Gem::Specification.new do |s|
s.add_dependency "net-ssh-multi", "~> 1.1.0"
# CHEF-3027: The knife-cloud plugins require newer features from highline, core chef should not.
s.add_dependency "highline", ">= 1.6.9"
- %w{erubis moneta}.each { |gem| s.add_dependency gem }
+ s.add_dependency "erubis"
- # development_dependency thin: eventmachine 0.12.10 doesn't support Ruby 1.9 on Windows
%w(rdoc sdoc ronn rake rack rspec_junit_formatter).each { |gem| s.add_development_dependency gem }
%w(rspec-core rspec-expectations rspec-mocks).each { |gem| s.add_development_dependency gem, "~> 2.8.0" }
View
@@ -18,84 +18,13 @@
# limitations under the License.
#
-require 'set'
-require 'fileutils'
-require 'chef/log'
-require 'chef/config'
-require 'chef/client'
-require 'chef/mixin/convert_to_class_name'
-require 'singleton'
-require 'moneta'
+require 'digest'
class Chef
class ChecksumCache
- include Chef::Mixin::ConvertToClassName
- include ::Singleton
- attr_reader :moneta
-
- def initialize(*args)
- self.reset!(*args)
- end
-
- def reset!(backend=nil, options=nil)
- backend ||= Chef::Config[:cache_type]
- options ||= Chef::Config[:cache_options]
-
- begin
- require "moneta/#{convert_to_snake_case(backend, 'Moneta')}"
- require 'chef/monkey_patches/moneta'
- rescue LoadError => e
- Chef::Log.fatal("Could not load Moneta back end #{backend.inspect}")
- raise e
- end
-
- @moneta = Moneta.const_get(backend).new(options)
- end
-
- def self.reset_cache_validity
- @valid_cached_checksums = nil
- end
-
- Chef::Client.when_run_starts do |run_status|
- reset_cache_validity
- end
-
- def self.valid_cached_checksums
- @valid_cached_checksums ||= Set.new
- end
-
- def self.validate_checksum(checksum_key)
- valid_cached_checksums << checksum_key
- end
-
- def self.all_cached_checksums
- all_checksums_with_filenames = {}
-
- Dir[File.join(Chef::Config[:cache_options][:path], '*')].each do |cksum_file|
- all_checksums_with_filenames[File.basename(cksum_file)] = cksum_file
- end
- all_checksums_with_filenames
- end
-
- def self.cleanup_checksum_cache
- Chef::Log.debug("Cleaning the checksum cache")
- if (Chef::Config[:cache_type].to_s == "BasicFile")
- all_cached_checksums.each do |cache_key, cksum_cache_file|
- unless valid_cached_checksums.include?(cache_key)
- remove_unused_checksum(cksum_cache_file)
- end
- end
- end
- end
-
- Chef::Client.when_run_completes_successfully do |run_status|
- cleanup_checksum_cache
- end
-
- def self.remove_unused_checksum(checksum_file)
- Chef::Log.debug("Removing unused checksum cache file #{checksum_file}")
- FileUtils.rm(checksum_file)
+ def self.instance
+ @instance ||= new
end
def self.checksum_for_file(*args)
@@ -106,31 +35,12 @@ def validate_checksum(*args)
self.class.validate_checksum(*args)
end
- def checksum_for_file(file, key=nil)
- key ||= generate_key(file)
- fstat = File.stat(file)
- lookup_checksum(key, fstat) || generate_checksum(key, file, fstat)
- end
-
- def lookup_checksum(key, fstat)
- cached = fetch(key)
- if cached && file_unchanged?(cached, fstat)
- validate_checksum(key)
- cached["checksum"]
- else
- nil
- end
- end
-
- def generate_checksum(key, file, fstat)
- checksum = checksum_file(file, Digest::SHA256.new)
- moneta.store(key, {"mtime" => fstat.mtime.to_f, "checksum" => checksum})
- validate_checksum(key)
- checksum
+ def checksum_for_file(file)
+ generate_checksum(file)
end
- def generate_key(file, group="chef")
- "#{group}-file-#{file.gsub(/(#{File::SEPARATOR}|\.)/, '-')}"
+ def generate_checksum(file)
+ checksum_file(file, Digest::SHA256.new)
end
def self.generate_md5_checksum_for_file(*args)
@@ -147,26 +57,6 @@ def generate_md5_checksum(io)
private
- def fetch(key)
- @moneta.fetch(key)
- rescue ArgumentError => e
- Log.warn "Error loading cached checksum for key #{key.inspect}"
- Log.warn(e)
- repair_checksum_cache
- nil
- end
-
- def repair_checksum_cache
- Chef::Log.info("Removing invalid checksum cache files")
- Dir["#{Chef::Config[:cache_options][:path]}/*"].each do |file_path|
- File.unlink(file_path) unless File.size?(file_path)
- end
- end
-
- def file_unchanged?(cached, fstat)
- cached["mtime"].to_f == fstat.mtime.to_f
- end
-
def checksum_file(file, digest)
File.open(file, 'rb') { |f| checksum_io(f, digest) }
end
@@ -181,10 +71,3 @@ def checksum_io(io, digest)
end
end
-module Moneta
- module Defaults
- def default
- nil
- end
- end
-end
View
@@ -310,9 +310,7 @@ def self.formatters
start_handlers []
# Checksum Cache
- # Uses Moneta on the back-end
- cache_type "BasicFile"
- cache_options({ :path => platform_specific_path("/var/chef/cache/checksums"), :skip_expires => true })
+ cache_options({ :path => platform_specific_path("/var/chef/cache/checksums") })
# Set to false to silence Chef 11 deprecation warnings:
chef11_deprecation_warnings true
@@ -1,50 +0,0 @@
-#
-# Author:: Seth Chisamore (<schisamo@opscode.com>)
-# Copyright:: Copyright (c) 2011 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# ensure data is written and read in binary mode
-# stops "dump format error for symbol(0x75)" errors
-module Moneta
- class BasicFile
-
- def store(key, value, options = {})
- ensure_directory_created(::File.dirname(path(key)))
- ::File.open(path(key), "wb") do |file|
- if @expires
- data = {:value => value}
- if options[:expires_in]
- data[:expires_at] = Time.now + options[:expires_in]
- end
- contents = Marshal.dump(data)
- else
- contents = Marshal.dump(value)
- end
- file.puts(contents)
- end
- end
-
- def raw_get(key)
- if ::File.respond_to?(:binread)
- data = ::File.binread(path(key))
- else
- data = ::File.open(path(key),"rb") { |f| f.read }
- end
- Marshal.load(data)
- end
-
- end
-end
Oops, something went wrong.

0 comments on commit 2c460c1

Please sign in to comment.