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 Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCookbookCacheCleaner

Returns a new instance of CookbookCacheCleaner.



46
47
48
# File 'lib/chef/cookbook/synchronizer.rb', line 46

def initialize
  reset!
end

Instance Attribute Details

#skip_removalObject

Returns the value of attribute skip_removal.



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

def skip_removal
  @skip_removal
end

Instance Method Details

#cacheObject



59
60
61
# File 'lib/chef/cookbook/synchronizer.rb', line 59

def cache
  Chef::FileCache
end

#cleanup_file_cacheObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/chef/cookbook/synchronizer.rb', line 63

def cleanup_file_cache
  unless Chef::Config[:solo_legacy_mode] || skip_removal
    # 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 #{ChefUtils::Dist::Infra::CLIENT}.")
        cache.delete(cache_filename)
      end
    end
  else
    Chef::Log.info("Skipping removal of unused files from the cache")
  end
end

#mark_file_as_valid(cache_path) ⇒ Object



55
56
57
# File 'lib/chef/cookbook/synchronizer.rb', line 55

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

#reset!Object



50
51
52
53
# File 'lib/chef/cookbook/synchronizer.rb', line 50

def reset!
  @skip_removal = nil
  @valid_cache_entries = {}
end