brew/Library/Homebrew/cmd/uninstall.rb
Max Howell f02d81ecbf Create active symlinks for installed formula
Similar to the LinkedKegs record, we write a symlink for installed kegs to PREFIX/opt.

Unlike the linked-keg record, unlinking doesn't remove the link, only uninstalling, and keg-only formula have a record too.

The reason for this addition is so that formula that depend on keg-only formula can build against the opt directory and not the cellar keg. Thus surviving upgrades.

To enforce this fix_install_names and built were adapted to use the opt path.

Standard kegs also create an opt symlink so that caveats can now refer to the opt directory and thus provide steps that survive upgrades too.

Thus the choice of /opt. It is short, neat and the right choice: POSIX dictates that opt is for stand-alone prefixes of software.
2012-08-29 12:41:33 -04:00

49 lines
1.1 KiB
Ruby

require 'keg'
require 'formula'
module Homebrew extend self
def uninstall
raise KegUnspecifiedError if ARGV.named.empty?
if not ARGV.force?
ARGV.kegs.each do |keg|
puts "Uninstalling #{keg}..."
keg.unlink
keg.uninstall
rm_opt_link keg.fname
end
else
ARGV.named.each do |name|
name = Formula.canonical_name(name)
# FIXME canonical_name is insane
raise "Invalid usage" if name.include? '/'
rack = HOMEBREW_CELLAR/name
if rack.directory?
puts "Uninstalling #{name}..."
rack.children.each do |keg|
if keg.directory?
keg = Keg.new(keg)
keg.unlink
keg.rmtree
end
end
rack.rmtree
end
rm_opt_link name
end
end
rescue MultipleVersionsInstalledError => e
ofail e
puts "Use `brew remove --force #{e.name}` to remove all versions."
end
def rm_opt_link name
optlink = HOMEBREW_PREFIX/:opt/name
optlink.unlink if optlink.symlink?
end
end