From 51c4c84a3f39a64d4694beebd15952d2cf1ae664 Mon Sep 17 00:00:00 2001 From: "Tim D. Smith" Date: Sun, 2 Apr 2017 08:17:07 -0700 Subject: [PATCH] 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. --- Library/Homebrew/keg_relocate.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index 834cda7684..00e941ce2f 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -97,7 +97,12 @@ class Keg end 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 until io.eof?