53 lines
1.3 KiB
Ruby
Raw Normal View History

require 'keg'
require 'cmd/tap'
module Homebrew extend self
# $n and $d are used by the ObserverPathnameExtension to keep track of
# certain filesystem actions.
def prune
$n = 0
$d = 0
dirs = []
2013-05-15 12:45:39 -05:00
Keg::PRUNEABLE_DIRECTORIES.select(&:directory?).each do |dir|
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 ENV['HOMEBREW_KEEP_INFO'] and 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?
dirs << path
end
end
end
2013-05-15 12:45:39 -05:00
dirs.sort.reverse_each do |d|
if ARGV.dry_run? && d.children.empty?
puts "Would remove (empty directory): #{d}"
else
d.rmdir_if_possible
end
end
2013-05-15 12:45:39 -05:00
repair_taps unless ARGV.dry_run?
2013-05-15 12:45:39 -05:00
if $n == 0 && $d == 0
puts "Nothing pruned" if ARGV.verbose?
else
print "Pruned #{$n} symbolic links "
print "and #{$d} directories " if $d > 0
puts "from #{HOMEBREW_PREFIX}"
2013-05-15 12:45:39 -05:00
end unless ARGV.dry_run?
end
end