brew/Library/Homebrew/unlink.rb
Mike McQuaid 849034c368
Improve @-versioned formulae linking.
The way we currently handle @-versioned formulae linking is pretty
labourius:
- it requires extensive use of `link_overwrite` to avoid the `link`
  stage failing on certain install/upgrade scenarios
- we teach people to use `brew link --force` whenever they wish to
  link a versioned formulae when it's pretty obvious what's expected
  in that situation

Instead, let's:
- automatically unlink other versioned formulae when linking a
  versioned formula (either through `brew link` or `install`/`upgrade`
  /`reinstall`)
- notify the user what we've done (with the same messaging as if
  they had run `brew link` manually)
2020-10-29 13:35:03 +00:00

31 lines
760 B
Ruby

# typed: false
# frozen_string_literal: true
module Homebrew
# Provides helper methods for unlinking formulae and kegs with consistent output.
module Unlink
module_function
def unlink_versioned_formulae(formula, verbose: false)
formula.versioned_formulae
.select(&:linked?)
.map(&:any_installed_keg)
.compact
.select(&:directory?)
.each do |keg|
unlink(keg, verbose: verbose)
end
end
def unlink(keg, dry_run: false, verbose: false)
options = { dry_run: dry_run, verbose: verbose }
keg.lock do
print "Unlinking #{keg}... "
puts if verbose
puts "#{keg.unlink(**options)} symlinks removed"
end
end
end
end