From 7b408dffc91bf61f34fb75a6a91f37d2c46afe8f Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Fri, 11 Dec 2020 10:53:15 -0800 Subject: [PATCH] audit: Add check_repository_references Ensure that any references to HOMEBREW_REPOSITORY are within HOMEBREW_LIBRARY. --- Library/Homebrew/formula_cellar_checks.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index f896caaf47..7d074d571c 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -7,6 +7,8 @@ require "utils/shell" # # @api private module FormulaCellarChecks + REPOSITORY_AND_NOT_LIBRARY_REGEX = %r{#{HOMEBREW_REPOSITORY}(?!/Library/)}.freeze + def check_env_path(bin) # warn the user if stuff was installed outside of their PATH return unless bin.directory? @@ -207,6 +209,25 @@ module FormulaCellarChecks EOS end + def check_repository_references(prefix) + return unless prefix.directory? + + keg = Keg.new(prefix) + + matches = [] + keg.each_unique_file_matching(HOMEBREW_REPOSITORY) do |f| + matches << f.relative_path_from(keg.to_path) if f.read.match? REPOSITORY_AND_NOT_LIBRARY_REGEX + end + + return if matches.empty? + + <<~EOS + Files were found with references to the Homebrew repository directory + that are outside of the Library directory. The offending files are: + #{matches * "\n "} + EOS + end + def check_shim_references(prefix) return unless prefix.directory? @@ -292,6 +313,7 @@ module FormulaCellarChecks problem_if_output(check_elisp_dirname(formula.share, formula.name)) problem_if_output(check_elisp_root(formula.share, formula.name)) problem_if_output(check_python_packages(formula.lib, formula.deps)) + problem_if_output(check_repository_references(formula.prefix)) problem_if_output(check_shim_references(formula.prefix)) problem_if_output(check_plist(formula.prefix, formula.plist)) problem_if_output(check_python_symlinks(formula.name, formula.keg_only?))