diff --git a/Library/Homebrew/extend/os/mac/keg_relocate.rb b/Library/Homebrew/extend/os/mac/keg_relocate.rb index bb0b726493..25eae0a6cf 100644 --- a/Library/Homebrew/extend/os/mac/keg_relocate.rb +++ b/Library/Homebrew/extend/os/mac/keg_relocate.rb @@ -54,21 +54,20 @@ class Keg change_install_name(bad_name, new_name, file) unless new_name == bad_name end - # Count duplicate rpaths. We need to keep track of this ourselves - # because the MachO data is cached and this cache is not updated - # after modification with #delete_rpath. - rpath_dupe_count = Hash.new { |h, k| h[k] = -1 } - file.rpaths.each do |rpath| - rpath_dupe_count[rpath] += 1 - end + # Keep track of the rpath counts for deletion of duplicates. + # We need to track this here since we cache the MachO data [0] + # and this cache is not updated after modification with #delete_rpath. + # + # [0] See os/mac/mach.rb. + rpath_count = Hash.new { |h, k| h[k] = file.rpaths.count(k) } each_linkage_for(file, :rpaths) do |bad_name| - # Strip duplicate rpaths and rpaths rooted in the build directory + # Strip duplicate rpaths and rpaths rooted in the build directory. next if !bad_name.start_with?(HOMEBREW_TEMP.to_s) && !bad_name.start_with?(HOMEBREW_TEMP.realpath.to_s) && - (rpath_dupe_count[bad_name] <= 0) + (rpath_count[bad_name] == 1) - rpath_dupe_count[bad_name] -= 1 + rpath_count[bad_name] -= 1 delete_rpath(bad_name, file) end end