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
Conversation
Review period will end on 2022-03-08 at 00:00:00 UTC. |
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.
A few thoughts but fine as-is, thanks!
Review period ended. |
6bbb203
to
0128192
Compare
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.
Two optional style suggestions, feel free to ship as-is or after those have been applied. Thanks @danielnachun!
Library/Homebrew/keg_relocate.rb
Outdated
grep_args = ["--files-with-matches", | ||
"--perl-regexp", | ||
"--binary-files=text"] |
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.
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.
Library/Homebrew/keg_relocate.rb
Outdated
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? |
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.
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? |
0128192
to
1faa444
Compare
I made the style changes and am merging now. |
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 genericeach_unique_file
method that is called byeach_unique_file_matching
, that's totally fine with me. At the moment onlyeach_unique_file_matching
would need to calleach_unique_file
, but it's possible some future methods could also useeach_unique_file
as well.