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

cask/artifact/symlinked: allow --force to overwrite symbolic links #8537

Merged
merged 1 commit into from
Sep 3, 2020
Merged

cask/artifact/symlinked: allow --force to overwrite symbolic links #8537

merged 1 commit into from
Sep 3, 2020

Conversation

miccal
Copy link
Contributor

@miccal miccal commented Aug 30, 2020

  • 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 style with your changes locally?
  • Have you successfully run brew tests with your changes locally?

In a previous PR I changed how binary and manpage links were handled for casks to ensure that neither an existing file nor an existing symbolic link would be overwritten.

This change allows the --force flag to override this check, essentially using the same logic as in cask/artifact/moved.

I have tested this locally, and running brew cask install {something with a conflicting binary name} outputs the error:

Error: It seems there already exists a Binary at '/usr/local/bin/{conflicting name}'; not overwriting.

and hence the install fails, while running brew cask install --force {something with a conflicting binary name} outputs the warning:

Warning: It seems there already exists a Binary at '/usr/local/bin/{conflicting name}'; overwriting.

and the install succeeds.

This should (hopefully) resolve Homebrew/homebrew-cask#88401.

Ping @reitermarkus and @vitorgalvao for thoughts and review.

Thank you.

Sorry, something went wrong.

@reitermarkus
Copy link
Member

As mentioned in Homebrew/homebrew-cask#88401 (comment), we should only override if the symlink point to the same cask.

So we need some method like Caskroom.cask_for_path which returns the cask token if the given path points to the Caskroom.

@miccal
Copy link
Contributor Author

miccal commented Aug 31, 2020

As mentioned in Homebrew/homebrew-cask#88401 (comment), we should only override if the symlink point to the same cask.

So we need some method like Caskroom.cask_for_path which returns the cask token if the given path points to the Caskroom.

This will take me some time; please feel free to take over in this PR (or a new one if you prefer) if you wish.

@miccal miccal marked this pull request as draft August 31, 2020 01:41
@miccal miccal changed the title cask/artifact/symlinked: allow --force to overwrite files or links cask/artifact/symlinked: allow --force to overwrite symbolic links Aug 31, 2020
@miccal
Copy link
Contributor Author

miccal commented Aug 31, 2020

Ok, I have made some changes that get part of the way there. Running brew cask install {something with a conflicting name} outputs the error:

Error: It seems there already exists a Binary at '/usr/local/bin/{conflicting name}'; not overwriting.

regardless of wether {conflicting name} is a file or a symbolic link.

Running brew cask install --force {something with a conflicting name} outputs the error:

Error: It seems there already exists a Binary at '/usr/local/bin/{conflicting name}'; not overwriting.

if {conflicting name} is a file.

Running brew cask install --force {something with a conflicting name} outputs the warning:

Warning: It seems there already exists a Binary at '/usr/local/bin/{conflicting name}'; overwriting.

if {conflicting name} is a symbolic link.

@reitermarkus I will probably need some help with the last bit, namely checking if the symbolic link being over-written points to the same cask.

@miccal
Copy link
Contributor Author

miccal commented Aug 31, 2020

@reitermarkus I have an idea on how to achieve the desired result, but I am not sure if it will work, nor am I sure on how to do it exactly.

Let me try and explain ...

Before the create_filesystem_link step, source is pointing to:

/usr/local/Caskroom/{new cask name}/{new cask version}/{path to binary}/{new binary}

while target is pointing to:

/usr/local/bin/{old binary}

and I assume that target.readlink is pointing to:

/usr/local/Caskroom/{old cask name}/{old cask version}/{path to binary}/{old binary}

Now, if I have this correct, is there a way to extract {new cask name} from source and {old cask name} from target.readlink?

And if so, can we compare them and allow the overwrite if and only if {new cask name} = {old cask name}?

@reitermarkus
Copy link
Member

is there a way to extract {new cask name} from source and {old cask name} from target.readlink?

Not yet, that's why we need a helper function for that as I mentioned.

@miccal
Copy link
Contributor Author

miccal commented Sep 1, 2020

@reitermarkus and @vitorgalvao I have come up with a way to achieve the desired results for this -- explanation and testing results are given below. Apologies in advance for the long read!

Installing a test-cask both without --force and with --force when there exists a conflicting file in /usr/local/bin/ results in the error:

Error: It seems there is already a Binary at '/usr/local/bin/{file}'.

and the install fails.

Installing a test-cask both without --force and with --force when there exists a conflicting symbolic link in /usr/local/bin/ that is not related in any way to the test-cask results in the error:

Error: It seems there is already a Binary at '/usr/local/bin/{symlink}'.

and the install fails.

Installing a test-cask without --force when there exists a conflicting symbolic link in /usr/local/bin/ that is related to the test-cask results in the error:

Error: It seems there is already a Binary at '/usr/local/bin/{symlink}'.

and the install fails.

Installing a test-cask with --force when there exists a conflicting symbolic link in /usr/local/bin/ that is related to the test-cask in the warning:

Warning: It seems there is already a Binary at '/usr/local/bin/{symlink}'; overwriting.

and the install succeeds.

The main reason why I decided to implement the check via:

raise CaskError, "#{message}." unless cask.artifacts.to_s.include? target.readlink.to_s

is because the symbolic link that we want to be overwritten may not necessarily point to the Caskroom.

Let me illustrate this with two more examples:

For the cask chromium that includes a shimscript, there is a symbolic link:

/usr/local/bin/chromium

pointing to:

/usr/local/Caskroom/chromium/802933/chromium.wrapper.sh

and installing with --force results in the warning:

Warning: It seems there is already a Binary at '/usr/local/bin/chromium'; overwriting.

and the install succeeds. Note that in this case target.readlink points to the Caskroom.

For the cask suspicious-package that includes a binary, there is a symbolic link:

/usr/local/bin/spkg

pointing to:

/Applications/Suspicious Package.app/Contents/SharedSupport/spkg

and installing with --force results in the warning:

Warning: It seems there is already a Binary at '/usr/local/bin/spkg'; overwriting.

and the install succeeds. Note that in this case target.readlink does not point to the Caskroom.

Thank you.

@miccal miccal marked this pull request as ready for review September 1, 2020 15:34
@reitermarkus reitermarkus merged commit 233cac0 into Homebrew:master Sep 3, 2020
@reitermarkus
Copy link
Member

Thanks, @miccal!

@miccal
Copy link
Contributor Author

miccal commented Sep 3, 2020

No problem, and thank you for all your help @reitermarkus.

@miccal miccal deleted the cask_symlink branch September 3, 2020 06:21
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Dec 14, 2020
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Dec 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error using --force to install/update some already installed casks
3 participants