Cache pkgutil results at the source
This commit is contained in:
parent
a1e7d7177f
commit
d6ed7fea4a
@ -234,7 +234,9 @@ module MacOS extend self
|
||||
end
|
||||
|
||||
def pkgutil_info id
|
||||
`/usr/sbin/pkgutil --pkg-info "#{id}" 2>/dev/null`.strip
|
||||
(@pkginfo ||= {}).fetch(id.to_s) do
|
||||
@pkginfo[id.to_s] = `/usr/sbin/pkgutil --pkg-info "#{id}" 2>/dev/null`.strip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -182,16 +182,17 @@ module MacOS::CLT extend self
|
||||
!latest_version?
|
||||
end
|
||||
|
||||
def version
|
||||
# The pkgutils calls are slow, don't repeat if no CLT installed.
|
||||
return @version if @version_determined
|
||||
|
||||
@version_determined = true
|
||||
# Version string (a pretty damn long one) of the CLT package.
|
||||
# Note, that different ways to install the CLTs lead to different
|
||||
# version numbers.
|
||||
@version ||= [STANDALONE_PKG_ID, FROM_XCODE_PKG_ID].find do |id|
|
||||
MacOS.pkgutil_info(id) =~ /version: (.+)$/
|
||||
end && $1
|
||||
def version
|
||||
@version ||= detect_version
|
||||
end
|
||||
|
||||
def detect_version
|
||||
[STANDALONE_PKG_ID, FROM_XCODE_PKG_ID].find do |id|
|
||||
version = MacOS.pkgutil_info(id)[/version: (.+)$/, 1]
|
||||
return version if version
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user