-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Cleanup: Continue on error removing keg #2374
Cleanup: Continue on error removing keg #2374
Conversation
Library/Homebrew/cleanup.rb
Outdated
def self.cleanup_cellar | ||
Formula.installed.each do |formula| | ||
cleanup_formula formula | ||
def self.cleanup_cellar(formulae = Formula.installed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need a default argument here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use case of this is to have the command not duplicate the continue on fail logic. See https://github.com/Homebrew/brew/pull/2374/files#diff-8cc42f61c29a8f960250394cbc3319c4L24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, I misread, thanks.
Library/Homebrew/cleanup.rb
Outdated
def self.cleanup_cellar(formulae = Formula.installed) | ||
unremovable_kegs = [] | ||
formulae.each do |formula| | ||
cleanup_formula formula, unremovable_kegs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels weird to pass unremovable_kegs
as an argument; what about an instance variable instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I wasn't sure whether we needed to maintain the previous behavior of failing when cleanup_formula fails for individual calls, so I did it this way. I'll change this to use an instance variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using an instance variable also allows us to move the failure messaging to the command rather than the library functions. We can also continue onto the cache, logs, lockfiles etc when formula cleanup fails.
Library/Homebrew/cleanup.rb
Outdated
|
||
return if unremovable_kegs.empty? | ||
ofail <<-EOS.undent | ||
Could not cleanup old kegs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could not cleanup old kegs! Fix your permissions on:
Library/Homebrew/cleanup.rb
Outdated
return if unremovable_kegs.empty? | ||
ofail <<-EOS.undent | ||
Could not cleanup old kegs | ||
Check you have permission to remove the following folders in the cellar: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can roll this line into the previous one.
Library/Homebrew/cleanup.rb
Outdated
ofail <<-EOS.undent | ||
Could not cleanup old kegs | ||
Check you have permission to remove the following folders in the cellar: | ||
#{unremovable_kegs.join " "} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.join "\n "
ca19913
to
7181bd4
Compare
Broken test seems like it's a connection issue. Not sure if this will work for me or if it's locked to maintainers, but here goes nothing: |
Thanks @ilovezfs |
yw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One final nit then good to 🚢. Nice work!
Library/Homebrew/cleanup.rb
Outdated
|
||
def self.unremovable_kegs | ||
@unremovable_kegs | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these helper methods are needed; just write directly to the instance variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used externally from the Cleanup command. I wrote it this way for consistency with the two disk_cleanup_size
methods rather than a knowledge of idiomatic ruby (I'm a ruby n00b coming from a mostly C# background). I could reasonably drop the add_unremovable_keg
method, but I think the accessor needs to remain.
Is the following more idiomatic in ruby?
def self.unremovable_kegs
@unremovable_kegs ||= []
end
def cleanup_keg(keg)
# ...
unremovable_kegs << keg
or:
@unremovable_kegs = []
attr_accessor :unremovable_kegs
def cleanup_keg(keg)
# ...
unremovable_kegs << keg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with the first option based on not finding any instances of attr_reader through Homebrew where the class only has class methods.
Library/Homebrew/cmd/cleanup.rb
Outdated
def report_unremovable_kegs | ||
ofail <<-EOS.undent | ||
Could not cleanup old kegs! Fix your permissions on: | ||
#{unremovable_kegs.join "\n "} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a Cleanup. in front
A couple of quick questions: It might be best to update https://github.com/Homebrew/brew/blob/master/CONTRIBUTING.md with the answers to these questions as it would help others, instead of just me. |
One more question. This class only has class methods, should it be a module? Some of the ruby style guides I'm reading suggest this approach, others do not. |
We don't mind either way on Homebrew/brew as we use merge commits anyway.
Yeh although our Rubocop does most of the enforcing too.
We generally rely on tooling and CI rather than documentation as it's easier to keep up to date.
Yeh, that may make sense and could use |
@joshka Travis CI got upset. Can you force push here to kick it off again? Thanks! |
Fixes Homebrew#2355 Create unremovable_kegs instance var Check cellar cleanup failure after full cleanup completes Use module_function in Homebrew::Cleanup as we never instantiate the class
18bba9f
to
48fdd16
Compare
I wasn't sure if there was an easy way to force push without making a change, so instead I squashed the commits and rewrote the commit messages. I made no other changes other than this. |
Great work here (again) @joshka! |
brew tests
with your changes locally?Fixes #2355