module Rake::Cleaner
def cant_be_deleted?(path_name)
def cant_be_deleted?(path_name) File.exist?(path_name) && (!File.readable?(path_name) || !File.executable?(path_name)) end
def cleanup(file_name, **opts)
def cleanup(file_name, **opts) begin opts = { verbose: Rake.application.options.trace }.merge(opts) rm_r file_name, **opts rescue StandardError => ex puts "Failed to remove #{file_name}: #{ex}" unless file_already_gone?(file_name) end end
def cleanup_files(file_names)
def cleanup_files(file_names) file_names.each do |file_name| cleanup(file_name) end end
def file_already_gone?(file_name)
def file_already_gone?(file_name) return false if File.exist?(file_name) path = file_name prev = nil while path = File.dirname(path) return false if cant_be_deleted?(path) break if [prev, "."].include?(path) prev = path end true end