tap: CoreCaskTap#cask_tokens should always return short names

This seems to be a bug with how we handle name shortening for the
core cask tap. The core tap always returns short formula names
and returning long names from the core cask tap when not using
the API leads to unexpected behavior.

Specifically this can trick the `brew untap` command into thinking
that there aren't any installed casks in the core cask tap and that
it can be removed even when that is not the case.

One risk here is that the full names were used when caching
descriptions so descriptions could be out of date for people in
the short term though hopefully that's not the end of the world.
This commit is contained in:
apainintheneck 2024-03-09 17:02:34 -08:00
parent cd1f040949
commit 6e0e78cadd
2 changed files with 10 additions and 8 deletions

View File

@ -1059,6 +1059,12 @@ class AbstractCoreTap < Tap
instance.ensure_installed!
end
# @private
sig { params(file: Pathname).returns(String) }
def formula_file_to_name(file)
file.basename(".rb").to_s
end
# @private
sig { override.returns(T::Boolean) }
def should_report_analytics?
@ -1229,12 +1235,6 @@ class CoreTap < AbstractCoreTap
end
end
# @private
sig { params(file: Pathname).returns(String) }
def formula_file_to_name(file)
file.basename(".rb").to_s
end
# @private
sig { params(file: Pathname).returns(String) }
def alias_file_to_name(file)

View File

@ -14,12 +14,14 @@ module Homebrew
Homebrew.with_no_api_env do
@name = tap.name
@path = tap.path
@cask_tokens = tap.cask_tokens
@tap_audit_exceptions = tap.audit_exceptions
@tap_style_exceptions = tap.style_exceptions
@tap_pypi_formula_mappings = tap.pypi_formula_mappings
@problems = []
@cask_tokens = tap.cask_tokens.map do |cask_token|
cask_token.split("/").last
end
@formula_aliases = tap.aliases.map do |formula_alias|
formula_alias.split("/").last
end
@ -83,7 +85,7 @@ module Homebrew
invalid_formulae_casks = list.select do |formula_or_cask_name|
formula_names.exclude?(formula_or_cask_name) &&
formula_aliases.exclude?(formula_or_cask_name) &&
cask_tokens.exclude?("#{@name}/#{formula_or_cask_name}")
cask_tokens.exclude?(formula_or_cask_name)
end
return if invalid_formulae_casks.empty?