From 44032802117ba261bf128cb9332e073f6e40fdc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVidisha?= <“vidishanevatia@gmail.com”> Date: Mon, 16 Dec 2024 22:20:29 -0800 Subject: [PATCH] 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 --- Library/Homebrew/cmd/list.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 78e3e8e2b8..080dc25585 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -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?