brew/Library/Homebrew/cmd/upgrade.rb
Jack Nagel 86e7c8a772 upgrade: unlink relative to the correct keg
Calling Keg#unlink on "#{f.rack}/#{f.version}" will perform the unlink
relative to the _new_ keg, rather than the keg we are upgrading from.
Fix this by resolving the linked_keg entry and unlinking relative to it.

Fixes Homebrew/homebrew#10296.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
2012-02-20 15:14:31 -06:00

48 lines
1.4 KiB
Ruby

require 'cmd/outdated'
require 'cmd/install'
class Fixnum
def plural_s
if self > 1 then "s" else "" end
end
end
module Homebrew extend self
def upgrade
Homebrew.perform_preinstall_checks
outdated = if ARGV.named.empty?
Homebrew.outdated_brews
else
ARGV.formulae.each do |f|
raise "#{f} already upgraded" if f.installed?
raise "#{f} not installed" unless f.rack.exist? and not f.rack.children.empty?
end
end
# Expand the outdated list to include outdated dependencies then sort and
# reduce such that dependencies are installed first and installation is not
# attempted twice. Sorting is implicit the way `recursive_deps` returns
# root dependencies at the head of the list and `uniq` keeps the first
# element it encounters and discards the rest.
outdated.map!{ |f| f.recursive_deps.reject{ |d| d.installed?} << f }
outdated.flatten!
outdated.uniq!
if outdated.length > 1
oh1 "Upgrading #{outdated.length} outdated package#{outdated.length.plural_s}, with result:"
puts outdated.map{ |f| "#{f.name} #{f.version}" } * ", "
end
outdated.each do |f|
installer = FormulaInstaller.new f
installer.show_header = false
oh1 "Upgrading #{f.name}"
installer.install
Keg.new(f.linked_keg.realpath).unlink if f.linked_keg.directory?
installer.caveats
installer.finish # includes link step
end
end
end