Merge pull request #5467 from MikeMcQuaid/cleanup-runs-prune
cleanup: run and replace `brew prune`.
This commit is contained in:
commit
2deacc7331
@ -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
|
||||
|
||||
@ -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` [<options>]
|
||||
|
||||
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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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).
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user