cmd/list: fix duplicate casks when symlinks exist

When a cask is renamed (e.g. logi-options-plus to logi-options+),
Homebrew creates a symlink in the Caskroom directory. Currently,
`brew list --cask` shows both the original and symlinked cask as
separate entries. This patch modifies the listing logic to resolve
symlinks and show only unique casks.

Fixes #18849
This commit is contained in:
“Vidisha 2024-12-16 22:20:29 -08:00
parent d43fa1f84e
commit 4403280211

View File

@ -214,7 +214,15 @@ module Homebrew
sig { void }
def list_casks
casks = if args.no_named?
Cask::Caskroom.casks
cask_paths = Cask::Caskroom.path.children.map do |path|
if path.symlink?
real_path = path.realpath
real_path.basename.to_s
else
path.basename.to_s
end
end.uniq
cask_paths.map { |name| Cask::CaskLoader.load(name) }
else
filtered_args = args.named.dup.delete_if do |n|
Homebrew.failed = true unless Cask::Caskroom.path.join(n).exist?