bottle: prioritize HOMEBREW_CELLAR over :any over :any_skip_relocation#6969
Conversation
dd80948 to
1afe4af
Compare
6028791 to
c2f923b
Compare
There was a problem hiding this comment.
Not sure I understand the .min here. Can you explain?
There was a problem hiding this comment.
It will return the minimum value from those 2 cellars.
HOMEBREW_CELLAR < :any < :any_skip_relocation.
That was @sjackman idea and it works well.
There was a problem hiding this comment.
Is that just based on a string comparison? If so it's a bit confusing and I think an if/else or a case statement might be a bit more obvious with intent.
There was a problem hiding this comment.
Yep, just based on string comparison. /… sorts before any sorts before any_skip_relocation. I'm personally okay with this style, so long as the comment precedes the code. The code to manually sort it could be a bit tedious. If we go that route, I'd suggesting creating a comparison function for this member and call [first, second].min { |a, b| … }
There was a problem hiding this comment.
If I've understood correctly: how about:
| [first, second].min | |
| cellars = [first, second] | |
| if cellars.include?(HOMEBREW_CELLAR) | |
| HOMEBREW_CELLAR | |
| elsif cellars.include?(:any) | |
| :any | |
| elsif cellars.include?(:any_skip_relocation) | |
| :any_skip_relocation | |
| else | |
| second | |
| end |
There was a problem hiding this comment.
This code doesn't handle the case when the cellar is the default path from the other OS or a non default path. How about:
if cellars.include?(HOMEBREW_CELLAR)
HOMEBREW_CELLAR
elsif first.start_with?("/")
first
elsif second.start_with?("/")
second
elsif cellars.include?(:any)
:any
else
:any_skip_relocation
endThere was a problem hiding this comment.
Would probably want to see an elsif cellars.include?(:any_skip_relocation) partly just to ensure this code survives being changed in future (as an else it makes me a bit uneasy).
8469d9f to
8ace72e
Compare
8ace72e to
c80107c
Compare
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Nice work, thanks @dawidd6!
|
Thank you, Dawid! |
brew stylewith your changes locally?brew testswith your changes locally?This is an example from @sjackman on what is the issue:
As one can see, there are two different cellars and the less proper one is chosen.
After applying the patch from this PR: