diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 3ab5645c4f..c252e7f1a3 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -163,6 +163,7 @@ module Homebrew cleanup_old_cache_db rm_ds_store + prune_prefix_symlinks_and_directories else args.each do |arg| formula = begin @@ -358,5 +359,51 @@ module Homebrew print_stderr: false end end + + def prune_prefix_symlinks_and_directories + ObserverPathnameExtension.reset_counts! + + dirs = [] + + Keg::MUST_EXIST_SUBDIRECTORIES.each do |dir| + next unless dir.directory? + + dir.find do |path| + path.extend(ObserverPathnameExtension) + if path.symlink? + unless path.resolved_path_exists? + if path.to_s =~ Keg::INFOFILE_RX + path.uninstall_info unless dry_run? + end + + if dry_run? + puts "Would remove (broken link): #{path}" + else + path.unlink + end + end + elsif path.directory? && !Keg::MUST_EXIST_SUBDIRECTORIES.include?(path) + dirs << path + end + end + end + + dirs.reverse_each do |d| + if dry_run? && d.children.empty? + puts "Would remove (empty directory): #{d}" + else + d.rmdir_if_possible + end + end + + return if dry_run? + + return if ObserverPathnameExtension.total.zero? + + n, d = ObserverPathnameExtension.counts + print "Pruned #{n} symbolic links " + print "and #{d} directories " if d.positive? + puts "from #{HOMEBREW_PREFIX}" + end end end diff --git a/Library/Homebrew/cmd/prune.rb b/Library/Homebrew/cmd/prune.rb index ba3d768edd..daebb892f4 100644 --- a/Library/Homebrew/cmd/prune.rb +++ b/Library/Homebrew/cmd/prune.rb @@ -1,12 +1,9 @@ #: * `prune` [`--dry-run`]: -#: Remove dead symlinks from the Homebrew prefix. This is generally not -#: needed, but can be useful when doing DIY installations. -#: -#: If `--dry-run` or `-n` is passed, show what would be removed, but do not -#: actually remove anything. +#: Deprecated. Use `brew cleanup` instead. require "keg" require "cli_parser" +require "cleanup" module Homebrew module_function @@ -16,8 +13,7 @@ module Homebrew usage_banner <<~EOS `prune` [] - Remove dead symlinks from the Homebrew prefix. This is generally not - needed, but can be useful when doing DIY installations. + Deprecated. Use `brew cleanup` instead. EOS switch "-n", "--dry-run", description: "Show what would be removed, but do not actually remove anything." @@ -29,50 +25,8 @@ module Homebrew def prune prune_args.parse - ObserverPathnameExtension.reset_counts! - - dirs = [] - - Keg::MUST_EXIST_SUBDIRECTORIES.each do |dir| - next unless dir.directory? - - dir.find do |path| - path.extend(ObserverPathnameExtension) - if path.symlink? - unless path.resolved_path_exists? - if path.to_s =~ Keg::INFOFILE_RX - path.uninstall_info unless ARGV.dry_run? - end - - if args.dry_run? - puts "Would remove (broken link): #{path}" - else - path.unlink - end - end - elsif path.directory? && !Keg::MUST_EXIST_SUBDIRECTORIES.include?(path) - dirs << path - end - end - end - - dirs.reverse_each do |d| - if ARGV.dry_run? && d.children.empty? - puts "Would remove (empty directory): #{d}" - else - d.rmdir_if_possible - end - end - - return if args.dry_run? - - if ObserverPathnameExtension.total.zero? - puts "Nothing pruned" if args.verbose? - else - n, d = ObserverPathnameExtension.counts - print "Pruned #{n} symbolic links " - print "and #{d} directories " if d.positive? - puts "from #{HOMEBREW_PREFIX}" - end + # TODO: deprecate and hide from manpage for next minor release. + # odeprecated("'brew prune'", "'brew cleanup'") + Cleanup.new(dry_run: args.dry_run?).prune_prefix_symlinks_and_directories end end diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 4122e1365b..71411637cd 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -342,8 +342,8 @@ class Reporter ohai "#{name} has been moved to Homebrew Cask." ohai "brew unlink #{name}" system HOMEBREW_BREW_FILE, "unlink", name - ohai "brew prune" - system HOMEBREW_BREW_FILE, "prune" + ohai "brew cleanup" + system HOMEBREW_BREW_FILE, "cleanup" ohai "brew cask install #{new_name}" system HOMEBREW_BREW_FILE, "cask", "install", new_name ohai <<~EOS diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 03b2d557e4..2794a7f616 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -288,7 +288,7 @@ module Homebrew return if broken_symlinks.empty? inject_file_list broken_symlinks, <<~EOS - Broken symlinks were found. Remove them with `brew prune`: + Broken symlinks were found. Remove them with `brew cleanup`: EOS end diff --git a/Library/Homebrew/test/cmd/prune_spec.rb b/Library/Homebrew/test/cmd/prune_spec.rb index c5a9df70c5..1c63d12561 100644 --- a/Library/Homebrew/test/cmd/prune_spec.rb +++ b/Library/Homebrew/test/cmd/prune_spec.rb @@ -19,10 +19,5 @@ describe "brew prune", :integration_test do expect(share/"pruneable").not_to be_a_directory expect(share/"notpruneable").to be_a_directory expect(share/"pruneable_symlink").not_to be_a_symlink - - expect { brew "prune", "--verbose" } - .to output(/Nothing pruned/).to_stdout - .and not_to_output.to_stderr - .and be_a_success end end diff --git a/docs/Manpage.md b/docs/Manpage.md index 398c6ce93e..5344ec294e 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -409,11 +409,7 @@ these flags should only appear after a command. Rerun the post-install steps for *`formula`*. * `prune` [`--dry-run`]: - Remove dead symlinks from the Homebrew prefix. This is generally not - needed, but can be useful when doing DIY installations. - - If `--dry-run` or `-n` is passed, show what would be removed, but do not - actually remove anything. + Deprecated. Use `brew cleanup` instead. * `readall` [`--aliases`] [`--syntax`] [*`taps`*]: Import all formulae from specified *`taps`* (defaults to all installed taps). diff --git a/manpages/brew-cask.1 b/manpages/brew-cask.1 index b4fcb96601..7f546ba296 100644 --- a/manpages/brew-cask.1 +++ b/manpages/brew-cask.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW\-CASK" "1" "December 2018" "Homebrew" "brew-cask" +.TH "BREW\-CASK" "1" "January 2019" "Homebrew" "brew-cask" . .SH "NAME" \fBbrew\-cask\fR \- a friendly binary installer for macOS diff --git a/manpages/brew.1 b/manpages/brew.1 index 4f3b762ab2..c3763335e5 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "BREW" "1" "December 2018" "Homebrew" "brew" +.TH "BREW" "1" "January 2019" "Homebrew" "brew" . .SH "NAME" \fBbrew\fR \- The missing package manager for macOS @@ -416,10 +416,7 @@ Rerun the post\-install steps for \fIformula\fR\. . .TP \fBprune\fR [\fB\-\-dry\-run\fR] -Remove dead symlinks from the Homebrew prefix\. This is generally not needed, but can be useful when doing DIY installations\. -. -.IP -If \fB\-\-dry\-run\fR or \fB\-n\fR is passed, show what would be removed, but do not actually remove anything\. +Deprecated\. Use \fBbrew cleanup\fR instead\. . .TP \fBreadall\fR [\fB\-\-aliases\fR] [\fB\-\-syntax\fR] [\fItaps\fR]