diff options
| author | Jack Nagel | 2013-12-17 20:46:42 -0600 |
|---|---|---|
| committer | Jack Nagel | 2013-12-17 21:13:23 -0600 |
| commit | a6602740f86e23f6a0500e9df6be0c45b367315c (patch) | |
| tree | af6b359b3e242fc5c54304d8273b4dfb3f5fb104 /Library/Homebrew/cmd | |
| parent | 4e11656e01f4f182bf7357b2bedc2fb4f1be1fa2 (diff) | |
| download | brew-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/Homebrew/cmd')
| -rw-r--r-- | Library/Homebrew/cmd/bottle.rb | 32 |
1 files changed, 10 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 |
