Read if no block is passed to Utils.popen_read

This commit is contained in:
Jack Nagel 2014-07-11 15:51:19 -05:00
parent 677cd51977
commit 5c24b7330b
3 changed files with 8 additions and 4 deletions

View File

@ -231,13 +231,13 @@ module OS
def mdfind(*ids) def mdfind(*ids)
return [] unless OS.mac? return [] unless OS.mac?
(@mdfind ||= {}).fetch(ids) do (@mdfind ||= {}).fetch(ids) do
@mdfind[ids] = Utils.popen_read("/usr/bin/mdfind", mdfind_query(*ids), &:read).split("\n") @mdfind[ids] = Utils.popen_read("/usr/bin/mdfind", mdfind_query(*ids)).split("\n")
end end
end end
def pkgutil_info(id) def pkgutil_info(id)
(@pkginfo ||= {}).fetch(id) do |key| (@pkginfo ||= {}).fetch(id) do |key|
@pkginfo[key] = Utils.popen_read("/usr/sbin/pkgutil", "--pkg-info", key, &:read).strip @pkginfo[key] = Utils.popen_read("/usr/sbin/pkgutil", "--pkg-info", key).strip
end end
end end

View File

@ -57,7 +57,7 @@ module OS
def version_from_mdls(path) def version_from_mdls(path)
version = Utils.popen_read( version = Utils.popen_read(
"/usr/bin/mdls", "-raw", "-nullMarker", "", "-name", "kMDItemVersion", path.to_s, &:read "/usr/bin/mdls", "-raw", "-nullMarker", "", "-name", "kMDItemVersion", path.to_s
).strip ).strip
version unless version.empty? version unless version.empty?
end end

View File

@ -10,7 +10,11 @@ module Utils
def self.popen(args, mode) def self.popen(args, mode)
IO.popen("-", mode) do |pipe| IO.popen("-", mode) do |pipe|
if pipe if pipe
if block_given?
yield pipe yield pipe
else
return pipe.read
end
else else
STDERR.reopen("/dev/null", "w") STDERR.reopen("/dev/null", "w")
exec(*args) exec(*args)