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

Use cask tab to better identify installed casks #17821

Closed
Closed
Changes from all commits
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
19 changes: 18 additions & 1 deletion Library/Homebrew/cask/caskroom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ def self.tokens
paths.map { |path| path.basename.to_s }
end

sig { returns(T::Array[String]) }
def self.full_tokens
require "cask/tab"

paths.map do |path|
token = path.basename.to_s
# Cask tabs were only added on July 13, 2024 in
# https://github.com/Homebrew/brew/pull/17554 so
# they might not exist for older installs.
if (tab_path = path/".metadata"/AbstractTab::FILENAME).exist?
tap = Tab.from_file(tab_path).tap
token = "#{tap}/#{token}" if tap&.installed?
end
token
end
end

sig { returns(T::Boolean) }
def self.any_casks_installed?
paths.any?
Expand Down Expand Up @@ -55,7 +72,7 @@ def self.ensure_caskroom_exists
# @api internal
sig { params(config: T.nilable(Config)).returns(T::Array[Cask]) }
def self.casks(config: nil)
tokens.sort.filter_map do |token|
full_tokens.sort.filter_map do |token|
CaskLoader.load(token, config:, warn: false)
rescue TapCaskAmbiguityError => e
T.must(e.loaders.first).load(config:)
Expand Down