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

formula: reject only the latest head keg when cleaning up #11475

Merged
merged 1 commit into from Jun 1, 2021

Conversation

Rylan12
Copy link
Member

@Rylan12 Rylan12 commented Jun 1, 2021

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

Follow up to #11438. See #11438 (comment)

Versions can be compared to each other using so using .sort_by(&:version) works fine. HeadVersions, though, cannot be compared in this way. Instead, the latest version is found by checking the time the tab was modified (done in Formula#latest_head_version).

Since .sort_by(&:version) on and array of HEAD kegs just returns the same array (of which all items except for the last were selected for cleanup), it is arbitrary which HEAD version doesn't get selected for cleanup.

Instead of sorting the HEAD keg array, I've chosen to just remove the latest HEAD keg as found using Formula#latest_head_version. This is essentially the same behavior that existed prior to #11438.

Here's the net diff of #11438 and this PR:

        eligible_kegs = if head? && (head_prefix = latest_head_prefix)
-         installed_kegs - [Keg.new(head_prefix)]
+         head, stable = installed_kegs.partition { |k| k.version.head? }
+         # Remove newest head and stable kegs
+         head - [Keg.new(head_prefix)] + stable.sort_by(&:version).slice(0...-1)
        else

@Rylan12 Rylan12 added the critical Critical change which should be shipped as soon as possible. label Jun 1, 2021
@Rylan12 Rylan12 requested a review from carlocab June 1, 2021 07:34
@BrewTestBot
Copy link
Member

Review period skipped due to critical label.

Copy link
Member

@carlocab carlocab left a comment

Choose a reason for hiding this comment

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

Makes sense to me. Thanks @Rylan12!

@Rylan12 Rylan12 merged commit b8479ad into Homebrew:master Jun 1, 2021
@Rylan12 Rylan12 deleted the fix-eligible_kegs_for_cleanup branch June 1, 2021 15:12
@github-actions github-actions bot added the outdated PR was locked due to age label Jul 2, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants