Merge pull request #20442 from HuaDeity/fix-head-install-with-forbid-packages-from-paths

Fix HEAD installations with HOMEBREW_FORBID_PACKAGES_FROM_PATHS
This commit is contained in:
Mike McQuaid 2025-08-13 12:35:38 +00:00 committed by GitHub
commit 023bbfdf5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -617,7 +617,8 @@ module Formulary
return unless path.expand_path.exist? return unless path.expand_path.exist?
return if Homebrew::EnvConfig.forbid_packages_from_paths? && return if Homebrew::EnvConfig.forbid_packages_from_paths? &&
!path.realpath.to_s.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/") !path.realpath.to_s.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/",
"#{HOMEBREW_CACHE}/")
if (tap = Tap.from_path(path)) if (tap = Tap.from_path(path))
# Only treat symlinks in taps as aliases. # Only treat symlinks in taps as aliases.

View File

@ -141,6 +141,21 @@ RSpec.describe Formulary do
end.to raise_error(FormulaUnavailableError) end.to raise_error(FormulaUnavailableError)
end end
it "allows cache paths even when paths are disabled" do
ENV["HOMEBREW_FORBID_PACKAGES_FROM_PATHS"] = "1"
cache_dir = HOMEBREW_CACHE/"test_formula_cache"
cache_dir.mkpath
cache_formula_path = cache_dir/formula_path.basename
FileUtils.cp formula_path, cache_formula_path
begin
formula = described_class.factory(cache_formula_path)
expect(formula).to be_a(Formula)
ensure
cache_formula_path.unlink if cache_formula_path.exist?
cache_dir.rmdir if cache_dir.exist?
end
end
context "when given a bottle" do context "when given a bottle" do
subject(:formula) { described_class.factory(bottle) } subject(:formula) { described_class.factory(bottle) }