aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2013-12-17 20:46:42 -0600
committerJack Nagel2013-12-17 21:13:23 -0600
commita6602740f86e23f6a0500e9df6be0c45b367315c (patch)
treeaf6b359b3e242fc5c54304d8273b4dfb3f5fb104 /Library
parent4e11656e01f4f182bf7357b2bedc2fb4f1be1fa2 (diff)
downloadbrew-a6602740f86e23f6a0500e9df6be0c45b367315c.tar.bz2
bottle: extract method for enumerating files that match a string
This brings a (small) performance improvement as we yield the files as they are output by fgrep rather than waiting until fgrep is done to do any work.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/bottle.rb32
-rw-r--r--Library/Homebrew/keg_fix_install_names.rb12
2 files changed, 22 insertions, 22 deletions
diff --git a/Library/Homebrew/cmd/bottle.rb b/Library/Homebrew/cmd/bottle.rb
index 733734adb..7e44b606b 100644
--- a/Library/Homebrew/cmd/bottle.rb
+++ b/Library/Homebrew/cmd/bottle.rb
@@ -42,33 +42,17 @@ module Homebrew extend self
include Utils::Inreplace
end
- def uniq_by_ino(list)
- h = {}
- list.each do |e|
- ino = e.stat.ino
- h[ino] = e unless h.key? ino
- end
- h.values
- end
-
def keg_contains string, keg
if not ARGV.homebrew_developer?
return quiet_system 'fgrep', '--recursive', '--quiet', '--max-count=1', string, keg
end
- # Find all files that still reference the keg via a string search
- keg_ref_files = `/usr/bin/fgrep --files-with-matches --recursive "#{string}" "#{keg}" 2>/dev/null`.split("\n")
- keg_ref_files.map! { |file| Pathname.new(file) }.reject!(&:symlink?)
+ result = false
+ index = 0
- # If files are hardlinked, only check one of them
- keg_ref_files = uniq_by_ino(keg_ref_files)
+ keg.each_unique_file_matching(string) do |file|
+ opoo "String '#{string}' still exists in these files:" if index.zero?
- # If there are no files with that string found, return immediately
- return false if keg_ref_files.empty?
-
- # Start printing out each file and any extra information we can find
- opoo "String '#{string}' still exists in these files:"
- keg_ref_files.each do |file|
puts "#{Tty.red}#{file}#{Tty.reset}"
# Check dynamic library linkage. Importantly, do not run otool on static
@@ -97,9 +81,12 @@ module Homebrew extend self
puts " #{Tty.gray}-->#{Tty.reset} match '#{match}' at offset #{Tty.em}0x#{offset}#{Tty.reset}"
end
end
+
+ index += 1
+ result = true
end
- puts
- true
+
+ result
end
def bottle_output bottle
@@ -162,6 +149,7 @@ module Homebrew extend self
relocatable = !keg_contains(prefix_check, keg)
relocatable = !keg_contains(HOMEBREW_CELLAR, keg) && relocatable
+ puts unless relocatable
rescue Interrupt
ignore_interrupts { bottle_path.unlink if bottle_path.exist? }
raise
diff --git a/Library/Homebrew/keg_fix_install_names.rb b/Library/Homebrew/keg_fix_install_names.rb
index 2b9760379..4ef543838 100644
--- a/Library/Homebrew/keg_fix_install_names.rb
+++ b/Library/Homebrew/keg_fix_install_names.rb
@@ -78,6 +78,18 @@ class Keg
results.to_a
end
+ def each_unique_file_matching string
+ IO.popen("/usr/bin/fgrep -lr '#{string}' '#{self}' 2>/dev/null") do |io|
+ hardlinks = Set.new
+
+ until io.eof?
+ file = Pathname.new(io.readline.chomp)
+ next if file.symlink?
+ yield file if hardlinks.add? file.stat.ino
+ end
+ end
+ end
+
private
def install_name_tool(*args)