Method: R10K::Util::Purgeable#purge!

Defined in:
lib/r10k/util/purgeable.rb

#purge!(opts = {}) ⇒ Object

Forcibly remove all unmanaged content in ‘self.managed_directories`



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/r10k/util/purgeable.rb', line 62

def purge!(opts={})
  recurse = opts[:recurse] || false
  whitelist = opts[:whitelist] || []

  exclusions = self.respond_to?(:purge_exclusions) ? purge_exclusions : []

  stale = stale_contents(recurse, exclusions, whitelist)

  if stale.empty?
    logger.debug1 _("No unmanaged contents in %{managed_dirs}, nothing to purge") % {managed_dirs: managed_directories.join(', ')}
  else
    stale.each do |fpath|
      begin
        FileUtils.rm_r(fpath, :secure => true)
        logger.info _("Removing unmanaged path %{path}") % {path: fpath}
      rescue Errno::ENOENT
        # Don't log on ENOENT since we may encounter that from recursively deleting
        # this item's parent earlier in the purge.
      rescue
        logger.debug1 _("Unable to remove unmanaged path: %{path}") % {path: fpath}
      end
    end
  end
end