From 8e318d81bcbf88d1829cdfba8c390f553c8787a1 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 5 May 2020 08:34:07 +0100 Subject: [PATCH] formula: add pkgetc method. This should provide a more "type-safe" way of referring to the `etc` directories of other formulae e.g. https://github.com/Homebrew/homebrew-core/pull/54257 so that the output will change if the formula name changes. --- Library/Homebrew/formula.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 4e46d328b3..8c9f47f1e7 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -790,6 +790,14 @@ class Formula (HOMEBREW_PREFIX/"etc").extend(InstallRenamed) end + # A subdirectory of `etc` with the formula name suffixed. + # e.g. `$HOMEBREW_PREFIX/etc/openssl@1.1` + # Anything using `pkgetc.install` will not overwrite other files on + # e.g. upgrades but will write a new file named `*.default`. + def pkgetc + (HOMEBREW_PREFIX/"etc"/name).extend(InstallRenamed) + end + # The directory where the formula's variable files should be installed. # This directory is not inside the `HOMEBREW_CELLAR` so it persists # across upgrades. @@ -1080,7 +1088,7 @@ class Formula # keg's formula is deleted. begin keg = Keg.for(path) - rescue NotAKegError, Errno::ENOENT # rubocop:disable Lint/SuppressedException + rescue NotAKegError, Errno::ENOENT # file doesn't belong to any keg. else tab_tap = Tab.for_keg(keg).tap @@ -1089,7 +1097,7 @@ class Formula begin Formulary.factory(keg.name) - rescue FormulaUnavailableError # rubocop:disable Lint/SuppressedException + rescue FormulaUnavailableError # formula for this keg is deleted, so defer to whitelist rescue TapFormulaAmbiguityError, TapFormulaWithOldnameAmbiguityError return false # this keg belongs to another formula