Class: Chef::Checksum
- Defined in:
- lib/chef/checksum.rb,
lib/chef/checksum/storage/filesystem.rb
Overview
Chef::Checksum
Checksum for an individual file; e.g., used for sandbox/cookbook uploading to track which files the system already manages.
Defined Under Namespace
Classes: Storage
Instance Attribute Summary collapse
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#create_time ⇒ Object
Returns the value of attribute create_time.
-
#original_committed_file_location ⇒ Object
readonly
When a Checksum commits a sandboxed file to its final home in the checksum repo, this attribute will have the original on-disk path where the file was stored; it will be used if the commit is reverted to restore the sandbox to the pre-commit state.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
Class Method Summary collapse
Instance Method Summary collapse
-
#commit_sandbox_file(sandbox_file) ⇒ Object
Moves the given
sandbox_fileinto the checksum repo using the path given byfile_locationand saves the Checksum to the database. -
#initialize(checksum = nil) ⇒ Checksum
constructor
Creates a new Chef::Checksum object.
-
#purge ⇒ Object
Removes the on-disk file backing this checksum object, then removes it from the database.
-
#revert_sandbox_file_commit ⇒ Object
Moves the checksum file back to its pre-commit location and deletes the checksum object from the database, effectively undoing
commit_sandbox_file. - #to_json(*a) ⇒ Object
Constructor Details
#initialize(checksum = nil) ⇒ Checksum
Creates a new Chef::Checksum object.
Arguments
- checksum:
-
the MD5 content hash of the file
Returns
- object<Chef::Checksum>
-
Duh. :)
43 44 45 46 47 48 |
# File 'lib/chef/checksum.rb', line 43 def initialize(checksum=nil) @create_time = Time.now.iso8601 @checksum = checksum @original_committed_file_location = nil @storage = Storage::Filesystem.new(Chef::Config.checksum_path, checksum) end |
Instance Attribute Details
#checksum ⇒ Object
Returns the value of attribute checksum.
27 28 29 |
# File 'lib/chef/checksum.rb', line 27 def checksum @checksum end |
#create_time ⇒ Object
Returns the value of attribute create_time.
27 28 29 |
# File 'lib/chef/checksum.rb', line 27 def create_time @create_time end |
#original_committed_file_location ⇒ Object (readonly)
When a Checksum commits a sandboxed file to its final home in the checksum repo, this attribute will have the original on-disk path where the file was stored; it will be used if the commit is reverted to restore the sandbox to the pre-commit state.
35 36 37 |
# File 'lib/chef/checksum.rb', line 35 def original_committed_file_location @original_committed_file_location end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
29 30 31 |
# File 'lib/chef/checksum.rb', line 29 def storage @storage end |
Class Method Details
.json_create(o) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/chef/checksum.rb', line 61 def self.json_create(o) checksum = new(o['checksum']) checksum.create_time = o['create_time'] checksum end |
Instance Method Details
#commit_sandbox_file(sandbox_file) ⇒ Object
Moves the given sandbox_file into the checksum repo using the path given by file_location and saves the Checksum to the database
70 71 72 73 74 |
# File 'lib/chef/checksum.rb', line 70 def commit_sandbox_file(sandbox_file) @original_committed_file_location = sandbox_file Chef::Log.info("Commiting sandbox file: move #{sandbox_file} to #{@storage}") @storage.commit(sandbox_file) end |
#purge ⇒ Object
Removes the on-disk file backing this checksum object, then removes it from the database
92 93 94 |
# File 'lib/chef/checksum.rb', line 92 def purge purge_file end |
#revert_sandbox_file_commit ⇒ Object
Moves the checksum file back to its pre-commit location and deletes the checksum object from the database, effectively undoing commit_sandbox_file. Raises Chef::Exceptions::IllegalChecksumRevert if the original file location is unknown, which is will be the case if commit_sandbox_file was not previously called
81 82 83 84 85 86 87 88 |
# File 'lib/chef/checksum.rb', line 81 def revert_sandbox_file_commit unless original_committed_file_location raise Chef::Exceptions::IllegalChecksumRevert, "Checksum #{self.inspect} cannot be reverted because the original sandbox file location is not known" end Chef::Log.warn("Reverting sandbox file commit: moving #{@storage} back to #{original_committed_file_location}") @storage.revert(original_committed_file_location) end |
#to_json(*a) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/chef/checksum.rb', line 50 def to_json(*a) result = { :checksum => checksum, :create_time => create_time, :json_class => self.class.name, :chef_type => 'checksum', :name => checksum } result.to_json(*a) end |