Skip to content

Symlinks from old cask tokens are not removed during uninstallation #19951

Open
@EricFromCanada

Description

@EricFromCanada

brew doctor output

$ brew doctor
Your system is ready to brew.

Verification

  • My "brew doctor output" above says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update twice and am still able to reproduce my issue.
  • This issue's title and/or description do not reference a single formula e.g. brew install wget. If they do, open an issue at https://github.com/Homebrew/homebrew-core/issues/new/choose instead.

brew config output

HOMEBREW_VERSION: 4.5.2-64-gbdf738e-dirty
ORIGIN: https://github.com/Homebrew/brew
HEAD: bdf738ef109a0960b14fba73c3e847991037fbef
Last commit: 2 hours ago
Branch: master
Core tap HEAD: 0d52e2fdafb916f7cb2ba3bdcd9fa552e744ac95
Core tap last commit: 2 hours ago
Core tap JSON: 15 May 15:05 UTC
Core cask tap HEAD: 25165d050fbf9ea7911474d3b5c53249c9806af8
Core cask tap last commit: 43 minutes ago
Core cask tap JSON: 15 May 15:05 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_AUTO_UPDATE_SECS: 3000
HOMEBREW_CASK_OPTS: ["--no-quarantine"]
HOMEBREW_DEVELOPER: set
HOMEBREW_EDITOR: bbedit
HOMEBREW_EVAL_ALL: set
HOMEBREW_GITHUB_API_TOKEN: set
HOMEBREW_MAKE_JOBS: 12
HOMEBREW_NO_AUTOREMOVE: set
HOMEBREW_NO_INSTALL_FROM_API: set
HOMEBREW_NO_UPDATE_REPORT_NEW: set
HOMEBREW_SORBET_RUNTIME: set
HOMEBREW_UPGRADE_GREEDY: set
Homebrew Ruby: 3.4.4 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.4/bin/ruby
CPU: dodeca-core 64-bit arm_lobos
Clang: 16.0.0 build 1600
Git: 2.47.1 => /opt/homebrew/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 14.7.4-arm64
CLT: 16.2.0.0.1.1733547573
Xcode: 16.2
Rosetta 2: false

What were you trying to do (and why)?

Uninstall a recently-migrated cask.

What happened (include all command output)?

The cask's Caskroom folder was removed, but not the symlink pointing to it.

What did you expect to happen?

Both the folder and symlink to be removed.

Step-by-step reproduction instructions (by running brew commands)

If a renamed cask is migrated to the new name, a symlink from the old name to the new is added to the Caskroom.

$ ls -l `brew --caskroom` | grep dolphin
drwxr-xr-x  4 eric  admin  128 15 May 12:35 dolphin@beta

$ brew migrate --cask -n dolphin@beta
==> Would migrate cask dolphin@beta to dolphin
cp -r /opt/homebrew/Caskroom/dolphin@beta /opt/homebrew/Caskroom/dolphin
mv /opt/homebrew/Caskroom/dolphin/.metadata/2503a/20250515163555.793/Casks/dolphin@beta.rb /opt/homebrew/Caskroom/dolphin/.metadata/2503a/20250515163555.793/Casks/dolphin.rb
rm -r /opt/homebrew/Caskroom/dolphin@beta
ln -s dolphin /opt/homebrew/Caskroom/dolphin@beta

$ brew migrate --cask dolphin@beta
==> Migrating cask dolphin@beta to dolphin

$ ls -l `brew --caskroom` | grep dolphin
drwxr-xr-x  4 eric  admin  128 15 May 13:20 dolphin
lrwxr-xr-x  1 eric  admin    7 15 May 13:20 dolphin@beta -> dolphin

If the renamed cask is uninstalled, whether with the original or new token, the symlink is not removed.

$ brew uninstall --cask dolphin -d
...
==> Uninstalling Cask dolphin
/opt/homebrew/Library/Homebrew/brew.rb (Cask::CaskLoader::FromPathLoader): loading /opt/homebrew/Caskroom/dolphin/.metadata/2503a/20250515163555.793/Casks/dolphin.rb
/opt/homebrew/Library/Homebrew/brew.rb (Cask::CaskLoader::FromPathLoader): loading /opt/homebrew/Caskroom/dolphin/.metadata/2503a/20250515163555.793/Casks/dolphin.rb
==> Uninstalling Cask dolphin
==> Uninstalling artifacts
==> 2 artifacts defined
#<Cask::ArtifactSet: {#<Cask::Artifact::App:0x0000000112390e28 @cask=#<Cask dolphin /opt/homebrew/Caskroom/dolphin/.metadata/2503a/20250515163555.793/Casks/dolphin.rb>, @dsl_args=["Dolphin.app"], @source_string="Dolphin.app", @target_string="">, #<Cask::Artifact::Zap:0x00000001127352e0 @cask=#<Cask dolphin /opt/homebrew/Caskroom/dolphin/.metadata/2503a/20250515163555.793/Casks/dolphin.rb>, @dsl_args=[{trash: ["~/Library/Application Support/Dolphin", "~/Library/Preferences/org.dolphin-emu.dolphin.plist"]}], @directives={trash: ["~/Library/Application Support/Dolphin", "~/Library/Preferences/org.dolphin-emu.dolphin.plist"], signal: []}>}>
==> Uninstalling artifact of class Cask::Artifact::App
==> Backing App 'Dolphin.app' up to '/opt/homebrew/Caskroom/dolphin/2503a/Dolphin.app'
/usr/bin/env /bin/cp -pR /Applications/Dolphin.app /opt/homebrew/Caskroom/dolphin/2503a/Dolphin.app
==> Removing App '/Applications/Dolphin.app'
==> Purging files for version 2503a of Cask dolphin
==> @cask.old_tokens: []

$ ls -l `brew --caskroom` | grep dolphin
lrwxr-xr-x  1 eric  admin    7 15 May 13:20 dolphin@beta -> dolphin

The problem seems to be that the instance of @cask in cask/installer.rb has an empty old_tokens attribute: https://github.com/Homebrew/brew/blob/master/Library/Homebrew/cask/installer.rb#L640-L644

Metadata

Metadata

Assignees

No one assigned

    Labels

    caskHomebrew Caskhelp wantedWe want help addressing this

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions