Use popen wrapper

Closes Homebrew/homebrew#30678.
This commit is contained in:
Jack Nagel 2014-07-05 13:50:54 -05:00
parent ad27b21cd1
commit 2d8a3ac35a
6 changed files with 8 additions and 11 deletions

View File

@ -63,7 +63,7 @@ module Homebrew
end end
# Use strings to search through the file for each string # Use strings to search through the file for each string
IO.popen("strings -t x - '#{file}'", "rb") do |io| Utils.popen_read("strings", "-t", "x", "-", file.to_s) do |io|
until io.eof? until io.eof?
str = io.readline.chomp str = io.readline.chomp
@ -168,8 +168,8 @@ module Homebrew
prefix_check = HOMEBREW_PREFIX prefix_check = HOMEBREW_PREFIX
end end
relocatable = !keg_contains(prefix_check, keg) relocatable = !keg_contains(prefix_check.to_s, keg)
relocatable = !keg_contains(HOMEBREW_CELLAR, keg) && relocatable relocatable = !keg_contains(HOMEBREW_CELLAR.to_s, keg) && relocatable
puts if !relocatable && ARGV.verbose? puts if !relocatable && ARGV.verbose?
rescue Interrupt rescue Interrupt
ignore_interrupts { bottle_path.unlink if bottle_path.exist? } ignore_interrupts { bottle_path.unlink if bottle_path.exist? }

View File

@ -27,7 +27,7 @@ class Volumes
def get_mounts path=nil def get_mounts path=nil
vols = [] vols = []
# get the volume of path, if path is nil returns all volumes # get the volume of path, if path is nil returns all volumes
raw_df = IO.popen("/bin/df -P #{path}", "rb", &:read) raw_df = Utils.popen_read("/bin/df", "-P", path, &:read)
raw_df.split("\n").each do |line| raw_df.split("\n").each do |line|
case line case line
# regex matches: /dev/disk0s2 489562928 440803616 48247312 91% / # regex matches: /dev/disk0s2 489562928 440803616 48247312 91% /

View File

@ -144,7 +144,7 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
def buffered_write(tool) def buffered_write(tool)
target = File.basename(basename_without_params, tarball_path.extname) target = File.basename(basename_without_params, tarball_path.extname)
IO.popen("#{tool} -f '#{tarball_path}' -c", "rb") do |pipe| Utils.popen_read(tool, "-f", tarball_path.to_s, "-c") do |pipe|
File.open(target, "wb") do |f| File.open(target, "wb") do |f|
buf = "" buf = ""
f.write(buf) while pipe.read(1024, buf) f.write(buf) while pipe.read(1024, buf)

View File

@ -39,7 +39,7 @@ class FormulaVersions
def rev_list(branch="HEAD") def rev_list(branch="HEAD")
repository.cd do repository.cd do
IO.popen("git rev-list --abbrev-commit --remove-empty #{branch} -- #{entry_name}") do |io| Utils.popen_read("git", "rev-list", "--abbrev-commit", "--remove-empty", branch, "--", entry_name) do |io|
yield io.readline.chomp until io.eof? yield io.readline.chomp until io.eof?
end end
end end

View File

@ -86,7 +86,7 @@ class Keg
end end
def each_unique_file_matching string def each_unique_file_matching string
IO.popen("/usr/bin/fgrep -lr '#{string}' '#{self}' 2>/dev/null", "rb") do |io| Utils.popen_read("/usr/bin/fgrep", "-lr", string, to_s) do |io|
hardlinks = Set.new hardlinks = Set.new
until io.eof? until io.eof?

View File

@ -140,10 +140,7 @@ module MacCPUs
def sysctl_bool(property) def sysctl_bool(property)
(@properties ||= {}).fetch(property) do (@properties ||= {}).fetch(property) do
result = nil result = Utils.popen_read("/usr/sbin/sysctl", "-n", property, &:gets).to_i
IO.popen("/usr/sbin/sysctl -n '#{property}' 2>/dev/null") do |f|
result = f.gets.to_i # should be 0 or 1
end
# sysctl call succeded and printed 1 # sysctl call succeded and printed 1
@properties[property] = $?.success? && result == 1 @properties[property] = $?.success? && result == 1
end end