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

Cleanup: Continue on error removing keg #2374

Merged

Conversation

joshka
Copy link
Contributor

@joshka joshka commented Mar 21, 2017

  • 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 tests with your changes locally?

Fixes #2355

def self.cleanup_cellar
Formula.installed.each do |formula|
cleanup_formula formula
def self.cleanup_cellar(formulae = Formula.installed)
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha, I misread, thanks.

def self.cleanup_cellar(formulae = Formula.installed)
unremovable_kegs = []
formulae.each do |formula|
cleanup_formula formula, unremovable_kegs
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.


return if unremovable_kegs.empty?
ofail <<-EOS.undent
Could not cleanup old kegs
Copy link
Member

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:

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:
Copy link
Member

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.

ofail <<-EOS.undent
Could not cleanup old kegs
Check you have permission to remove the following folders in the cellar:
#{unremovable_kegs.join " "}
Copy link
Member

Choose a reason for hiding this comment

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

.join "\n "

@joshka joshka force-pushed the cleanup-command-continue-on-error branch 2 times, most recently from ca19913 to 7181bd4 Compare March 23, 2017 03:06
@joshka
Copy link
Contributor Author

joshka commented Mar 23, 2017

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:
@BrewTestBot test this please

@ilovezfs ilovezfs closed this Mar 23, 2017
@ilovezfs ilovezfs reopened this Mar 23, 2017
@joshka
Copy link
Contributor Author

joshka commented Mar 23, 2017

Thanks @ilovezfs

@ilovezfs
Copy link
Contributor

yw

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a 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!


def self.unremovable_kegs
@unremovable_kegs
end
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

@joshka joshka Mar 23, 2017

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.

def report_unremovable_kegs
ofail <<-EOS.undent
Could not cleanup old kegs! Fix your permissions on:
#{unremovable_kegs.join "\n "}
Copy link
Contributor Author

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

@joshka
Copy link
Contributor Author

joshka commented Mar 23, 2017

A couple of quick questions:
Do you prefer commits to be rebased prior to merge?
Is your preferred style guide the github one?

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.

@joshka
Copy link
Contributor Author

joshka commented Mar 23, 2017

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.

@MikeMcQuaid
Copy link
Member

Do you prefer commits to be rebased prior to merge?

We don't mind either way on Homebrew/brew as we use merge commits anyway.

Is your preferred style guide the github one?

Yeh although our Rubocop does most of the enforcing too.

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.

We generally rely on tooling and CI rather than documentation as it's easier to keep up to date.

This class only has class methods, should it be a module?

Yeh, that may make sense and could use module_function on it. Feel free to add to this PR?

@MikeMcQuaid
Copy link
Member

@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
@joshka joshka force-pushed the cleanup-command-continue-on-error branch from 18bba9f to 48fdd16 Compare March 31, 2017 06:48
@joshka
Copy link
Contributor Author

joshka commented Mar 31, 2017

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.

@MikeMcQuaid MikeMcQuaid merged commit 80b39bb into Homebrew:master Mar 31, 2017
@MikeMcQuaid
Copy link
Member

Great work here (again) @joshka!

@Homebrew Homebrew locked and limited conversation to collaborators May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants