cleanup: run and replace brew prune.
It's always seemed a bit pointless to me that we have both of these commands. Given we're doing more and more to recommend (and eventually, safely, automatically run (see #4760) `brew cleanup` let's roll their functionality into a single command.
This commit is contained in:
parent
d92ed91170
commit
8cfcc7fcf0
@ -163,6 +163,7 @@ module Homebrew
|
|||||||
|
|
||||||
cleanup_old_cache_db
|
cleanup_old_cache_db
|
||||||
rm_ds_store
|
rm_ds_store
|
||||||
|
prune_prefix_symlinks_and_directories
|
||||||
else
|
else
|
||||||
args.each do |arg|
|
args.each do |arg|
|
||||||
formula = begin
|
formula = begin
|
||||||
@ -358,5 +359,51 @@ module Homebrew
|
|||||||
print_stderr: false
|
print_stderr: false
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
#: * `prune` [`--dry-run`]:
|
#: * `prune` [`--dry-run`]:
|
||||||
#: Remove dead symlinks from the Homebrew prefix. This is generally not
|
#: Deprecated. Use `brew cleanup` instead.
|
||||||
#: 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.
|
|
||||||
|
|
||||||
require "keg"
|
require "keg"
|
||||||
require "cli_parser"
|
require "cli_parser"
|
||||||
|
require "cleanup"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
module_function
|
module_function
|
||||||
@ -16,8 +13,7 @@ module Homebrew
|
|||||||
usage_banner <<~EOS
|
usage_banner <<~EOS
|
||||||
`prune` [<options>]
|
`prune` [<options>]
|
||||||
|
|
||||||
Remove dead symlinks from the Homebrew prefix. This is generally not
|
Deprecated. Use `brew cleanup` instead.
|
||||||
needed, but can be useful when doing DIY installations.
|
|
||||||
EOS
|
EOS
|
||||||
switch "-n", "--dry-run",
|
switch "-n", "--dry-run",
|
||||||
description: "Show what would be removed, but do not actually remove anything."
|
description: "Show what would be removed, but do not actually remove anything."
|
||||||
@ -29,50 +25,8 @@ module Homebrew
|
|||||||
def prune
|
def prune
|
||||||
prune_args.parse
|
prune_args.parse
|
||||||
|
|
||||||
ObserverPathnameExtension.reset_counts!
|
# TODO: deprecate and hide from manpage for next minor release.
|
||||||
|
# odeprecated("'brew prune'", "'brew cleanup'")
|
||||||
dirs = []
|
Cleanup.new(dry_run: args.dry_run?).prune_prefix_symlinks_and_directories
|
||||||
|
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -342,8 +342,8 @@ class Reporter
|
|||||||
ohai "#{name} has been moved to Homebrew Cask."
|
ohai "#{name} has been moved to Homebrew Cask."
|
||||||
ohai "brew unlink #{name}"
|
ohai "brew unlink #{name}"
|
||||||
system HOMEBREW_BREW_FILE, "unlink", name
|
system HOMEBREW_BREW_FILE, "unlink", name
|
||||||
ohai "brew prune"
|
ohai "brew cleanup"
|
||||||
system HOMEBREW_BREW_FILE, "prune"
|
system HOMEBREW_BREW_FILE, "cleanup"
|
||||||
ohai "brew cask install #{new_name}"
|
ohai "brew cask install #{new_name}"
|
||||||
system HOMEBREW_BREW_FILE, "cask", "install", new_name
|
system HOMEBREW_BREW_FILE, "cask", "install", new_name
|
||||||
ohai <<~EOS
|
ohai <<~EOS
|
||||||
|
|||||||
@ -288,7 +288,7 @@ module Homebrew
|
|||||||
return if broken_symlinks.empty?
|
return if broken_symlinks.empty?
|
||||||
|
|
||||||
inject_file_list broken_symlinks, <<~EOS
|
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
|
EOS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -19,10 +19,5 @@ describe "brew prune", :integration_test do
|
|||||||
expect(share/"pruneable").not_to be_a_directory
|
expect(share/"pruneable").not_to be_a_directory
|
||||||
expect(share/"notpruneable").to be_a_directory
|
expect(share/"notpruneable").to be_a_directory
|
||||||
expect(share/"pruneable_symlink").not_to be_a_symlink
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@ -409,11 +409,7 @@ these flags should only appear after a command.
|
|||||||
Rerun the post-install steps for *`formula`*.
|
Rerun the post-install steps for *`formula`*.
|
||||||
|
|
||||||
* `prune` [`--dry-run`]:
|
* `prune` [`--dry-run`]:
|
||||||
Remove dead symlinks from the Homebrew prefix. This is generally not
|
Deprecated. Use `brew cleanup` instead.
|
||||||
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.
|
|
||||||
|
|
||||||
* `readall` [`--aliases`] [`--syntax`] [*`taps`*]:
|
* `readall` [`--aliases`] [`--syntax`] [*`taps`*]:
|
||||||
Import all formulae from specified *`taps`* (defaults to all installed taps).
|
Import all formulae from specified *`taps`* (defaults to all installed taps).
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
.\" generated with Ronn/v0.7.3
|
.\" generated with Ronn/v0.7.3
|
||||||
.\" http://github.com/rtomayko/ronn/tree/0.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"
|
.SH "NAME"
|
||||||
\fBbrew\-cask\fR \- a friendly binary installer for macOS
|
\fBbrew\-cask\fR \- a friendly binary installer for macOS
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
.\" generated with Ronn/v0.7.3
|
.\" generated with Ronn/v0.7.3
|
||||||
.\" http://github.com/rtomayko/ronn/tree/0.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"
|
.SH "NAME"
|
||||||
\fBbrew\fR \- The missing package manager for macOS
|
\fBbrew\fR \- The missing package manager for macOS
|
||||||
@ -416,10 +416,7 @@ Rerun the post\-install steps for \fIformula\fR\.
|
|||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fBprune\fR [\fB\-\-dry\-run\fR]
|
\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\.
|
Deprecated\. Use \fBbrew cleanup\fR instead\.
|
||||||
.
|
|
||||||
.IP
|
|
||||||
If \fB\-\-dry\-run\fR or \fB\-n\fR is passed, show what would be removed, but do not actually remove anything\.
|
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fBreadall\fR [\fB\-\-aliases\fR] [\fB\-\-syntax\fR] [\fItaps\fR]
|
\fBreadall\fR [\fB\-\-aliases\fR] [\fB\-\-syntax\fR] [\fItaps\fR]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user