Class: Chef::CookbookCacheCleaner

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/chef/cookbook/synchronizer.rb

Overview

Keep track of the filenames that we use in both eager cookbook downloading (during sync_cookbooks) and lazy (during the run itself, through FileVendor). After the run is over, clean up the cache.

Instance Method Summary collapse

Constructor Details

#initializeCookbookCacheCleaner

Returns a new instance of CookbookCacheCleaner.



26
27
28
# File 'lib/chef/cookbook/synchronizer.rb', line 26

def initialize
  reset!
end

Instance Method Details

#cacheObject



38
39
40
# File 'lib/chef/cookbook/synchronizer.rb', line 38

def cache
  Chef::FileCache
end

#cleanup_file_cacheObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/chef/cookbook/synchronizer.rb', line 42

def cleanup_file_cache
  unless Chef::Config[:solo]
    # Delete each file in the cache that we didn't encounter in the
    # manifest.
    cache.find(File.join(%w{cookbooks ** *})).each do |cache_filename|
      unless @valid_cache_entries[cache_filename]
        Chef::Log.info("Removing #{cache_filename} from the cache; it is no longer needed by chef-client.")
        cache.delete(cache_filename)
      end
    end
  end
end

#mark_file_as_valid(cache_path) ⇒ Object



34
35
36
# File 'lib/chef/cookbook/synchronizer.rb', line 34

def mark_file_as_valid(cache_path)
  @valid_cache_entries[cache_path] = true
end

#reset!Object



30
31
32
# File 'lib/chef/cookbook/synchronizer.rb', line 30

def reset!
  @valid_cache_entries = {}
end