From 7384bd2b3fb2ac56f2908452f9a46a782e7cb956 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Thu, 18 Aug 2022 21:25:17 +0800 Subject: [PATCH] cleanup: use `cleanup_path` more consistently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `cleanup_path` already handles the dry-run logic, and also includes those paths in the summary of space freed by `brew cleanup`. Before this change: ❯ brew cleanup --dry-run Would remove: /Users/carlocab/Library/Caches/Homebrew/bootsnap (2,401 files, 41.9MB) After this change: ❯ brew cleanup --dry-run Would remove: /Users/carlocab/Library/Caches/Homebrew/bootsnap (2,401 files, 41.9MB) ==> This operation would free approximately 41.9MB of disk space. --- Library/Homebrew/cleanup.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 07e1438c84..72b325cb9e 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -428,7 +428,6 @@ module Homebrew next if !use_system_ruby && portable_ruby_latest_version == path.basename.to_s portable_rubies_to_remove << path - puts "Would remove: #{path} (#{path.abv})" if dry_run? end return if portable_rubies_to_remove.empty? @@ -440,20 +439,16 @@ module Homebrew puts Utils.popen_read("git", "-C", HOMEBREW_REPOSITORY, "clean", "-ffqx", bundler_path).chomp end - return if dry_run? - - FileUtils.rm_rf portable_rubies_to_remove + portable_rubies_to_remove.each do |portable_ruby| + cleanup_path(portable_ruby) { portable_ruby.rmtree } + end end def cleanup_bootsnap bootsnap = cache/"bootsnap" return unless bootsnap.exist? - if dry_run? - puts "Would remove: #{bootsnap} (#{bootsnap.abv})" - else - FileUtils.rm_rf bootsnap - end + cleanup_path(bootsnap) { bootsnap.rmtree } end def cleanup_cache_db(rack = nil)