Skip to content

Handle symlinked prefixes when linking kegs - #24376

Merged
MikeMcQuaid merged 3 commits into
Homebrew:mainfrom
iBug-forks:fix-symlink-prefix
Oct 29, 2026
Merged

MikeMcQuaid merged 3 commits into
Homebrew:mainfrom
iBug-forks:fix-symlink-prefix

Conversation

@iBug

@iBug iBug commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

  • 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 brew benchmark results.
  • 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.

I am using my custom setup that allows multiple Linux users to install Homebrew independently without conflict, by having a FUSE program present /home/linuxbrew/.linuxbrew as a symbolic link that points to the visiting user's home directory. This causes brew install and brew upgrade to intermittently attempt to operate on the root directory:

Error: An unexpected error occurred during the `brew link` step
The formula built, but is not symlinked into /home/linuxbrew/.linuxbrew
Permission denied @ dir_s_mkdir - /linuxbrew
Error: <irrelevant>: Permission denied @ dir_s_mkdir - /linuxbrew

This is reproduceable by having /home/linuxbrew/.linuxbrew as a symbolic link that points to somewhere else and trying to install certain formulae.

This PR fixes the issue described above.

AI Use Disclosure: Codex (GPT-5.6 Sol) identified the problem from the code and made the changes. I personally reviewed the changes before submitting this PR.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0cf616f0-115a-485d-824f-0846f780ff21
Commits

Reviewing files that changed from the base of the PR and between f545d24 and e47bf27.

Files selected for processing: 1
  • Library/Homebrew/test/keg_spec.rb
Files skipped from review as they are similar to previous changes: 1
  • Library/Homebrew/test/keg_spec.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where linking kegs with a symlinked installation prefix could make headers from another keg unavailable. Headers in nested directories now remain accessible when linking multiple kegs, including when those kegs contain different files in the same nested directory. This keeps the expected headers available under the installation prefix after linking.

Keg.for now constructs the keg path relative to the resolved Cellar path. A regression test checks that linking two kegs with a symlinked prefix leaves a nested header accessible.

Changes: Keg path resolution

Layer / File(s) Summary
Resolve Cellar paths and test symlinked-prefix linking
Library/Homebrew/keg.rb, Library/Homebrew/test/keg_spec.rb
Keg.for constructs the keg path from the Cellar constant and the input path relative to the resolved Cellar. The test checks that a nested header remains accessible after linking two kegs with a symlinked prefix.

Priority: Normal

Merge Risk: Minimal · up to e47bf

The reported symlinked-prefix linking failure is addressed, and the regression test checks that the header remains accessible after the merge. No actionable merge-blocking risk remains after normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Description check Passed The description clearly explains the symlinked-prefix linking failure, the intended fix, testing, and AI use disclosure.
Title check Passed The title clearly and concisely describes the main change: handling symlinked prefixes when linking kegs.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7363469b-4886-4f62-93dc-7e9bf103efa6
Commits

Reviewing files that changed from the base of the PR and between 6fb3f99 and 071d767.

Files selected for processing: 2
  • Library/Homebrew/keg.rb
  • Library/Homebrew/test/keg_spec.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Comment thread Library/Homebrew/keg.rb Resolved

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6dae099d-cff4-4871-8aa9-5445459631cf
Commits

Reviewing files that changed from the base of the PR and between 071d767 and f545d24.

Files selected for processing: 2
  • Library/Homebrew/keg.rb
  • Library/Homebrew/test/keg_spec.rb

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Comment thread Library/Homebrew/test/keg_spec.rb Resolved
@MikeMcQuaid

Copy link
Copy Markdown
Member

Is this the only issue you see with this configuration and everything else works perfectly? If so, surprising but cool. My concern is there's likely a bunch of failure states and we drip-drip PRs adding complexity for an unsupported configuration.

@iBug

iBug commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

Is this the only issue you see with this configuration and everything else works perfectly?

Surprisingly, yes. This is the only issue that I've run into in the past few months with this symlink setup.

It would be nice if we can have this case supported as, you know, Homebrew is not known for allowing each user to install their own copy other than having to recompile everything from scratch.

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, let's try this, thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Oct 29, 2026
Merged via the queue into Homebrew:main with commit 16d9042 Oct 29, 2026
53 checks passed
@iBug
iBug deleted the fix-symlink-prefix branch October 29, 2026 17:02
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

⌂ 换网址