Class: Chef::Cache::Checksum

Inherits:
Chef::Cache show all
Defined in:
lib/chef/cache/checksum.rb

Instance Attribute Summary

Attributes inherited from Chef::Cache

#moneta

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Chef::Cache

#initialize, #reset!

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string

Constructor Details

This class inherits a constructor from Chef::Cache

Class Method Details

.checksum_for_file(*args) ⇒ Object



27
28
29
# File 'lib/chef/cache/checksum.rb', line 27

def self.checksum_for_file(*args)
  instance.checksum_for_file(*args)
end

Instance Method Details

#checksum_for_file(file) ⇒ Object



31
32
33
34
# File 'lib/chef/cache/checksum.rb', line 31

def checksum_for_file(file)
  key, fstat = filename_to_key(file), File.stat(file)
  lookup_checksum(key, fstat) || generate_checksum(key, file, fstat)
end

#generate_checksum(key, file, fstat) ⇒ Object



45
46
47
48
49
# File 'lib/chef/cache/checksum.rb', line 45

def generate_checksum(key, file, fstat)
  checksum = checksum_file(file)
  moneta.store(key, {"mtime" => fstat.mtime.to_f, "checksum" => checksum})
  checksum
end

#lookup_checksum(key, fstat) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/chef/cache/checksum.rb', line 36

def lookup_checksum(key, fstat)
  cached = @moneta.fetch(key)
  if cached && file_unchanged?(cached, fstat)
    cached["checksum"]
  else
    nil
  end
end