Skip to content

Skip cask link when symlink already correct - #23428

Merged
MikeMcQuaid merged 1 commit into
mainfrom
symlink-target-check
Aug 4, 2026
Merged

Skip cask link when symlink already correct#23428
MikeMcQuaid merged 1 commit into
mainfrom
symlink-target-check

Conversation

@MikeMcQuaid

Copy link
Copy Markdown
Member
  • A plain brew upgrade raised "It seems there is already a Binary at ..." even when the existing symlink resolved to the exact source about to be linked, because the realpath check sat behind force/adopt. The revert left the symlink in place so every retry failed identically until manual intervention.
  • Treat an already-correct symlink as a no-op: log and skip the link. Genuine conflicts, such as a real file at the target or a symlink elsewhere, still require --force or --adopt.

Fixes #23426.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Fable 5 max with local review, iterating and testing.


Copilot AI lite review requested due to automatic review settings August 4, 2026 11:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request updates Cask artifact symlink handling so that attempting to link a cask binary does not error when the destination already contains the correct symlink, making repeated brew upgrade/retries idempotent in that scenario.

Changes:

  • Treat an already-correct existing symlink at the target path as a no-op (log and skip linking) instead of raising a conflict error.
  • Add an RSpec example to cover the “already correctly linked” symlink case for Cask::Artifact::Binary.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Library/Homebrew/cask/artifact/symlinked.rb Adds early-return path to skip relinking when the existing target symlink resolves to the same source.
Library/Homebrew/test/cask/artifact/binary_spec.rb Adds a regression test asserting the correct-symlink case is handled as a no-op and logs accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Library/Homebrew/cask/artifact/symlinked.rb Outdated
- A plain `brew upgrade` raised "It seems there is already a
  Binary at ..." even when the existing symlink resolved to the
  exact source about to be linked, because the realpath check sat
  behind `force`/`adopt`. The revert left the symlink in place so
  every retry failed identically until manual intervention.
- Treat an already-correct symlink as a no-op: log and skip the
  link. Genuine conflicts, such as a real file at the target or a
  symlink elsewhere, still require `--force` or `--adopt`.
- Rescue errors resolving the target, like `conflicting_formula`
  does, so unreadable symlinks fall back to the existing conflict
  and error handling instead of raising `Errno` exceptions.
- Fixes #23426.
@MikeMcQuaid
MikeMcQuaid force-pushed the symlink-target-check branch from 2b9adf0 to 0376eda Compare August 4, 2026 12:04
@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Aug 4, 2026
Merged via the queue into main with commit c04a10f Aug 4, 2026
42 checks passed
@MikeMcQuaid
MikeMcQuaid deleted the symlink-target-check branch August 4, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cask upgrade aborts when a symlinked artifact already exists at its exact target, wedging the cask permanently

3 participants