lib/ohai/plugins/joyent.rb in ohai-8.21.0 vs lib/ohai/plugins/joyent.rb in ohai-8.22.0

- old
+ new

@@ -23,27 +23,22 @@ provides "joyent" provides "virtualization/guest_id" depends "os", "platform", "virtualization" def collect_product_file - lines = [] - if ::File.exists?("/etc/product") - ::File.open("/etc/product") do |file| - while line = file.gets - lines << line - end - end + data = ::File.read("/etc/product") rescue nil + if data + data.strip.split("\n") + else + [] end - lines end def collect_pkgsrc - if File.exist?("/opt/local/etc/pkg_install.conf") - sm_pkgsrc = ::File.read("/opt/local/etc/pkg_install.conf").split("=") - sm_pkgsrc[1].chomp - else - nil + data = ::File.read("/opt/local/etc/pkg_install.conf") rescue nil + if data + /PKG_PATH=(.*)/.match(data)[1] rescue nil end end def is_smartos? platform == "smartos" @@ -74,9 +69,9 @@ joyent[:sm_baseimage_ver] = sm_baseimage[3] end end ## retrieve pkgsrc - joyent[:sm_pkgsrc] = collect_pkgsrc if collect_pkgsrc + joyent[:sm_pkgsrc] = collect_pkgsrc end end end