brew/Library/Homebrew/cmd/uninstall.rb
Jack Nagel 37a56fa513 FormulaInstaller: implement installation locks
FormulaInstaller now attempts to take a lock on a "foo.brewing" file for
the formula and all of its dependencies before attempting installation.

The lock is an advisory lock implemented using flock(), and as such it
only locks out other processes that attempt to take the lock. It also
means that it is never necessary to manually remove the lock file,
because the lock is not enforced by I/O.

The uninstall, link, and unlink commands all learn to respect this lock
as well, so that the installation cannot be corrupted by a concurrent
Homebrew process, and keg operations cannot occur simultaneously.
2013-01-26 12:14:45 -06:00

51 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|
keg.lock do
puts "Uninstalling #{keg}..."
keg.unlink
keg.uninstall
rm_opt_link keg.fname
end
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