Skip to content

Commit

Permalink
caskroom: add, use any_casks_installed?.
Browse files Browse the repository at this point in the history
Add a new method for the two places we're checking if we have any
casks installed. This is much more performance and user friendly than
attempting to load every cask.

Fixes #13027
  • Loading branch information
MikeMcQuaid committed Mar 30, 2022
1 parent 663c0a7 commit 61976e0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions Library/Homebrew/cask/caskroom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ module Caskroom

sig { returns(Pathname) }
def self.path
@path ||= HOMEBREW_PREFIX.join("Caskroom")
@path ||= HOMEBREW_PREFIX/"Caskroom"
end

sig { returns(T::Boolean) }
def self.any_casks_installed?
return false unless path.exist?

path.children.select(&:directory?).any?
end

sig { void }
Expand All @@ -36,7 +43,7 @@ def self.ensure_caskroom_exists
def self.casks(config: nil)
return [] unless path.exist?

Pathname.glob(path.join("*")).sort.select(&:directory?).map do |path|
path.children.select(&:directory?).sort.map do |path|
token = path.basename.to_s

if (tap_path = CaskLoader.tap_paths(token).first)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def doctor
check_missing_deps
]
methods = (checks.all - slow_checks) + slow_checks
methods -= checks.cask_checks if Cask::Caskroom.casks.blank?
methods -= checks.cask_checks unless Cask::Caskroom.any_casks_installed?
else
methods = args.named
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def list
ohai "Formulae" if $stdout.tty? && !args.formula?
safe_system "ls", *ls_args, HOMEBREW_CELLAR
end
if !args.formula? && Cask::Caskroom.casks.any?
if !args.formula? && Cask::Caskroom.any_casks_installed?
if $stdout.tty? && !args.cask?
puts
ohai "Casks"
Expand Down

0 comments on commit 61976e0

Please sign in to comment.