Don't follow symlinks when hunting for strings

When we're assessing whether a bottle is relocatable, we shouldn't have
to descend into symlink paths we encounter. This is supposed to be the
default behavior but it doesn't appear to be (perhaps because we pass a
symlink to the keg on the command line?).

All of the switches that control this behavior differ between BSD and
GNU grep, so sniff the grep flavor first.
This commit is contained in:
Tim D. Smith 2017-04-02 08:17:07 -07:00
parent 974b5e2fa2
commit 51c4c84a3f

View File

@ -97,7 +97,12 @@ class Keg
end end
def each_unique_file_matching(string) def each_unique_file_matching(string)
Utils.popen_read("/usr/bin/fgrep", "-lr", string, to_s) do |io| bsd = `/usr/bin/fgrep -V`.include?("BSD grep")
grep_args = "-lr"
# Don't recurse into symlinks; the man page says this is the default, but
# it's wrong.
grep_args += "O" if bsd
Utils.popen_read("/usr/bin/fgrep", grep_args, string, to_s) do |io|
hardlinks = Set.new hardlinks = Set.new
until io.eof? until io.eof?