Skip to content

Conversation

@boblail
Copy link
Contributor

@boblail boblail commented Dec 10, 2025

Every once in a while a user runs brew install --overwrite FORMULA and gets the error

Error: No such file or directory - /opt/homebrew/var/homebrew/linked/sq-satoolbox

The error is raised from Library/Homebrew/keg.rb:105 which is in a call stack trying to tell you that the formula is already linked.

But I'm suggesting we should not consider it be linked when the symlink is dangling. brew install will remediate the situation correectly anyway.


  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

Every once in a while a user runs `brew install --overwrite FORMULA` and gets the error
```
Error: No such file or directory - /opt/homebrew/var/homebrew/linked/sq-satoolbox
```

The error is raised from [Library/Homebrew/keg.rb:105](https://github.com/Homebrew/brew/blob/51b612b63b86fbb0fe4ee39b8756c7fb05d4e964/Library/Homebrew/keg.rb#L105) which is in a call stack trying to tell you that the formula is already linked.

But I'm suggesting we should not consider it be linked when the symlink is dangling. `brew install` will [remediate the situation correectly](https://github.com/Homebrew/brew/blob/51b612b63b86fbb0fe4ee39b8756c7fb05d4e964/Library/Homebrew/formula_installer.rb#L1161-L1164) anyway.
Copilot AI review requested due to automatic review settings December 10, 2025 22:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where brew install --overwrite would fail with "No such file or directory" errors when a dangling tracking link exists in /opt/homebrew/var/homebrew/linked/. The fix changes the Formula#linked? method to use exist? instead of symlink?, which properly treats dangling symlinks as "not linked" rather than causing errors downstream.

Key changes:

  • Modified Formula#linked? to use exist? check instead of symlink? to handle dangling symlinks correctly
  • This prevents Keg.for() from being called on non-existent paths, avoiding the ENOENT error
  • The change aligns with the existing pattern where Keg#linked? checks for both symlink existence and directory validity

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

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Makes sense, thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Dec 11, 2025
Merged via the queue into Homebrew:main with commit 4b94610 Dec 11, 2025
42 checks passed
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.

2 participants