Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link and conflicts_with options do not work as expected #1442

Open
ahawkins opened this issue Sep 4, 2024 · 1 comment
Open

link and conflicts_with options do not work as expected #1442

ahawkins opened this issue Sep 4, 2024 · 1 comment

Comments

@ahawkins
Copy link

ahawkins commented Sep 4, 2024

From the docs:

# 'brew install', always 'brew services restart', 'brew link', 'brew unlink mysql' (if it is installed)
brew "[email protected]", restart_service: true, link: true, conflicts_with: ["mysql"]

We want [email protected] installed and linked. So we have this in our Brewfile:

brew '[email protected]', link: true, conflicts_with: ["mysql"]

This does not work. The linking fails. Here's what happens.

$ brew install mysql
$ brew bundle
Using [email protected]
Error: Could not symlink bin/comp_err
Target /opt/homebrew/bin/comp_err
is a symlink belonging to mysql. You can unlink it:
  brew unlink mysql

To force the link and overwrite all conflicting files:
  brew link --overwrite [email protected]

To list all files that would be deleted:
  brew link --overwrite [email protected] --dry-run
Linking /opt/homebrew/Cellar/[email protected]/8.0.39_1...
Homebrew Bundle complete! 1 Brewfile dependency now installed.
$ echo $?
0

The linking fails. Also brew bundle incorrectly exits with status code 0 for successful execution. This is not true.

The docs reference a -f to force overwriting. This also does not work as expected. The brew link step fails in the same way:

$ brew bundle -f
Using [email protected]
Error: Could not symlink bin/comp_err
Target /opt/homebrew/bin/comp_err
is a symlink belonging to mysql. You can unlink it:
  brew unlink mysql

To force the link and overwrite all conflicting files:
  brew link --overwrite [email protected]

To list all files that would be deleted:
  brew link --overwrite [email protected] --dry-run
Linking /opt/homebrew/Cellar/[email protected]/8.0.39_1...
Homebrew Bundle complete! 1 Brewfile dependency now installed.
$ echo $?
0

Note the command still exits 0 even though a part failed.

The only way to resolve the issue is to manually run brew unlink mysql prior to brew bundle. This apparently defeats the purpose of the link and conflicts_with options.

$ brew unlink mysql
Unlinking /opt/homebrew/Cellar/mysql/9.0.1... 97 symlinks removed.
$ brew bundle
Using [email protected]
Homebrew Bundle complete! 1 Brewfile dependency now installed.
$ mysql --version
mysql  Ver 8.0.39 for macos14.4 on arm64 (Homebrew)

This issue seems similar to #932.

My Current bundle version

git:master >> pwd
/opt/homebrew/Library/Taps/homebrew/homebrew-bundle
git:master >> git show
commit 980753399e0bc5802610cd1eeacdb16cba53744b (HEAD -> master, origin/master, origin/HEAD)
Merge: d368f81 c33837a
Author: Patrick Linnane <[email protected]>
Date:   Tue Sep 3 15:15:48 2024 -0700

    Merge pull request #1441 from Homebrew/dependabot/bundler/rspec-core-3.13.1
@yelsa
Copy link
Contributor

yelsa commented Sep 27, 2024

The console output indicates you already have [email protected] installed (the Using [email protected] line).

Do a brew uninstall [email protected] and then retry the brew bundle step.

The code paths are different for new installs/upgrades vs when already installed.
The link option is processed in all cases, conflicts_with option is only used on new installs/upgrades.
Because [email protected] is already installed, no call to brew unlink mysql is made. Hence the link is in the way when the brew link --force [email protected] step is tried.

The brew link step is only a '--force' and not an '--overwrite'. A new install should call with a --force --overwrite if you pass -f but it looks like there is a very minor bug preventing that (I have a fix i'll PR in the next couple of days).
There is an unfinished PR to add a link: :overwrite option to the Brewfile spec #1116. This would address the already installed case. I'm looking at picking this up.

As to why the exit status code is 0. Well it only cares about whether things are successfully installed. Rightly or wrongly, link and service state failures aren't considered as part of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants