Class: Chef::Checksum::Storage::Filesystem

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/checksum/storage/filesystem.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_dir, checksum) ⇒ Filesystem

Returns a new instance of Filesystem



22
23
24
25
# File 'lib/chef/checksum/storage/filesystem.rb', line 22

def initialize(base_dir, checksum)
  @base_dir = base_dir
  @checksum = checksum
end

Instance Method Details

#checksum_repo_directoryObject



32
33
34
# File 'lib/chef/checksum/storage/filesystem.rb', line 32

def checksum_repo_directory
  File.join(Chef::Config.checksum_path, @checksum[0..1])
end

#commit(sandbox_file) ⇒ Object



36
37
38
39
# File 'lib/chef/checksum/storage/filesystem.rb', line 36

def commit(sandbox_file)
  FileUtils.mkdir_p(checksum_repo_directory)
  File.rename(sandbox_file, file_location)
end

#file_locationObject Also known as: to_s



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

def file_location
  File.join(checksum_repo_directory, @checksum)
end

#purgeObject

Deletes the file backing this checksum from the on-disk repo. Purging the checksums is how users can get back to a valid state if they've deleted files, so we silently swallow Errno::ENOENT here.



48
49
50
51
52
# File 'lib/chef/checksum/storage/filesystem.rb', line 48

def purge
  FileUtils.rm(file_location)
rescue Errno::ENOENT
  true
end

#revert(original_committed_file_location) ⇒ Object



41
42
43
# File 'lib/chef/checksum/storage/filesystem.rb', line 41

def revert(original_committed_file_location)
  File.rename(file_location, original_committed_file_location)
end