Class: Chef::CookbookCacheCleaner
- Inherits:
-
Object
- Object
- Chef::CookbookCacheCleaner
- 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
-
#skip_removal ⇒ Object
Returns the value of attribute skip_removal.
Instance Method Summary collapse
- #cache ⇒ Object
- #cleanup_file_cache ⇒ Object
-
#initialize ⇒ CookbookCacheCleaner
constructor
A new instance of CookbookCacheCleaner.
- #mark_file_as_valid(cache_path) ⇒ Object
- #reset! ⇒ Object
Constructor Details
#initialize ⇒ CookbookCacheCleaner
Returns a new instance of CookbookCacheCleaner.
45 46 47 |
# File 'lib/chef/cookbook/synchronizer.rb', line 45 def initialize reset! end |
Instance Attribute Details
#skip_removal ⇒ Object
Returns the value of attribute skip_removal.
30 31 32 |
# File 'lib/chef/cookbook/synchronizer.rb', line 30 def skip_removal @skip_removal end |
Instance Method Details
#cache ⇒ Object
58 59 60 |
# File 'lib/chef/cookbook/synchronizer.rb', line 58 def cache Chef::FileCache end |
#cleanup_file_cache ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/chef/cookbook/synchronizer.rb', line 62 def cleanup_file_cache unless Chef::Config[:solo_legacy_mode] || skip_removal if Chef::Config.target_mode? TargetIO::FileUtils.rm_rf(Chef::Config[:file_cache_path]) return end # 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
54 55 56 |
# File 'lib/chef/cookbook/synchronizer.rb', line 54 def mark_file_as_valid(cache_path) @valid_cache_entries[cache_path] = true end |
#reset! ⇒ Object
49 50 51 52 |
# File 'lib/chef/cookbook/synchronizer.rb', line 49 def reset! @skip_removal = nil @valid_cache_entries = {} end |