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

Use simpler method to detect binaries #12964

Merged
merged 3 commits into from Mar 10, 2022

Conversation

danielnachun
Copy link
Member

We discussed here: https://github.com/Homebrew/brew/pull/12940/files#r818284011 that it is much simpler to use grep to check if an individual file contains null bytes than to iterate over all files in the keg. We are only interested in checking files which we already know contain prefixes, which we can pass in as an argument. This method could also be useful in the future if we need to determine if files are binaries in other situations.

I also reverted each_unique_file_matching back to its original state. If we think it's better to still have a generic each_unique_file method that is called by each_unique_file_matching, that's totally fine with me. At the moment only each_unique_file_matching would need to call each_unique_file, but it's possible some future methods could also use each_unique_file as well.

@BrewTestBot
Copy link
Member

Review period will end on 2022-03-08 at 00:00:00 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Mar 6, 2022
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.

A few thoughts but fine as-is, thanks!

Library/Homebrew/extend/os/mac/keg_relocate.rb Outdated Show resolved Hide resolved
Library/Homebrew/keg_relocate.rb Outdated Show resolved Hide resolved
Library/Homebrew/keg_relocate.rb Outdated Show resolved Hide resolved
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Mar 8, 2022
@BrewTestBot
Copy link
Member

Review period ended.

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.

Two optional style suggestions, feel free to ship as-is or after those have been applied. Thanks @danielnachun!

Comment on lines 180 to 182
grep_args = ["--files-with-matches",
"--perl-regexp",
"--binary-files=text"]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
grep_args = ["--files-with-matches",
"--perl-regexp",
"--binary-files=text"]
grep_args = [
"--files-with-matches",
"--perl-regexp",
"--binary-files=text",
]

just if we decide to add/remove this later to make the diff nicer.

Utils.popen_read(grep_bin, grep_args, NULL_BYTE_STRING, to_s) do |io|
each_unique_file(io, block)
end
Utils.popen_read(grep_bin, *grep_args, NULL_BYTE_STRING, file).size.positive?
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Utils.popen_read(grep_bin, *grep_args, NULL_BYTE_STRING, file).size.positive?
Utils.popen_read(grep_bin, *grep_args, NULL_BYTE_STRING, file).present?

@danielnachun
Copy link
Member Author

I made the style changes and am merging now.

@danielnachun danielnachun merged commit d2857e0 into Homebrew:master Mar 10, 2022
@github-actions github-actions bot added the outdated PR was locked due to age label Apr 10, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 10, 2022
@danielnachun danielnachun deleted the new_binary_grep branch July 11, 2022 00:18
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.

None yet

3 participants