keg: don't delete main opt links of other formulae.

If an old alias, according to the tab, of a formula being upgraded (e.g.
python) has the same name as the main opt link of some other formula
(e.g. python@2), don't remove the main opt link of that other formula.

Specifically,

  brew install python@2
  brew upgrade python

should not accidentally delete /usr/local/opt/python@2 even though
python@2 used to be an alias of python.
This commit is contained in:
ilovezfs 2018-03-07 22:35:23 -08:00
parent eee6e98d90
commit f87a589129

View File

@ -256,7 +256,11 @@ class Keg
aliases.each do |a| aliases.each do |a|
alias_symlink = opt/a alias_symlink = opt/a
alias_symlink.delete if alias_symlink.symlink? || alias_symlink.exist? if alias_symlink.symlink? && alias_symlink.exist?
alias_symlink.delete if alias_symlink.realpath == opt_record.realpath
elsif alias_symlink.symlink? || alias_symlink.exist?
alias_symlink.delete
end
end end
Pathname.glob("#{opt_record}@*").each do |a| Pathname.glob("#{opt_record}@*").each do |a|