66 lines
1.7 KiB
Ruby
Raw Normal View History

2016-04-08 16:28:43 +02:00
#: * `prune` [`--dry-run`]:
#: Remove dead symlinks from the Homebrew prefix. This is generally not
#: needed, but can be useful when doing DIY installations. Also remove broken
#: app symlinks from `/Applications` and `~/Applications` that were previously
#: created by `brew linkapps`.
#:
#: If `--dry-run` or `-n` is passed, show what would be removed, but do not
#: actually remove anything.
require "keg"
require "cmd/tap"
require "cmd/unlinkapps"
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
def prune
ObserverPathnameExtension.reset_counts!
dirs = []
Keg::PRUNEABLE_DIRECTORIES.each do |dir|
next unless dir.directory?
2013-02-17 22:54:43 -06:00
dir.find do |path|
2013-05-15 12:45:39 -05:00
path.extend(ObserverPathnameExtension)
if path.symlink?
unless path.resolved_path_exists?
if path.to_s =~ Keg::INFOFILE_RX
2013-05-15 12:45:39 -05:00
path.uninstall_info unless ARGV.dry_run?
end
if ARGV.dry_run?
puts "Would remove (broken link): #{path}"
else
path.unlink
end
end
elsif path.directory? && !Keg::PRUNEABLE_DIRECTORIES.include?(path)
dirs << path
end
end
end
2013-12-21 21:37:26 -06:00
dirs.reverse_each do |d|
2013-05-15 12:45:39 -05:00
if ARGV.dry_run? && d.children.empty?
puts "Would remove (empty directory): #{d}"
else
d.rmdir_if_possible
end
end
2016-09-10 10:24:57 +01:00
unless ARGV.dry_run?
if ObserverPathnameExtension.total.zero?
puts "Nothing pruned" if ARGV.verbose?
else
n, d = ObserverPathnameExtension.counts
print "Pruned #{n} symbolic links "
2017-09-24 20:12:58 +01:00
print "and #{d} directories " if d.positive?
2016-09-10 10:24:57 +01:00
puts "from #{HOMEBREW_PREFIX}"
end
end
unlinkapps_prune(dry_run: ARGV.dry_run?, quiet: true)
end
end