Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formula_installer: restrict use of Formula from Keg #11532

Merged
merged 2 commits into from
Jun 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions Library/Homebrew/formula_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1076,10 +1076,30 @@ def post_install
#{HOMEBREW_LIBRARY_PATH}/postinstall.rb
]

args << if formula.local_bottle_path.present?
formula.prefix/".brew/#{formula.name}.rb"
else
formula.path
keg_formula_path = formula.opt_prefix/".brew/#{formula.name}.rb"
tap_formula_path = formula.path

# Use the formula from the keg if:
# * Installing from a local bottle, or
# * The formula doesn't exist in the tap (or the tap isn't installed), or
# * The formula in the tap has a different pkg_version.
# In all other cases, including if the formula from the keg is unreadable
# (third-party taps may `require` some of their own libraries), use the
# formula from the tap.
args << begin
keg_formula = Formulary.factory(keg_formula_path)
tap_formula = Formulary.factory(tap_formula_path) if tap_formula_path.exist?
other_version_installed = (keg_formula.pkg_version != tap_formula&.pkg_version)

if formula.local_bottle_path.present? ||
!tap_formula_path.exist? ||
other_version_installed
keg_formula_path
else
tap_formula_path
end
rescue FormulaUnreadableError
tap_formula_path
end

Utils.safe_fork do
Expand Down