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.
This commit is contained in:
parent
4e11656e01
commit
a6602740f8
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user