Sha256: a4d218013766b3522d01cfff49a72192e724aa7f577201d9eb50d343becbbff7

Contents?: true

Size: 1.64 KB

Versions: 16

Compression:

Stored size: 1.64 KB

Contents

#include <internal/facts/osx/operating_system_resolver.hpp>
#include <leatherman/execution/execution.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <string>

using namespace std;
using namespace facter::facts;
using namespace leatherman::execution;

namespace facter { namespace facts { namespace osx {

    operating_system_resolver::data operating_system_resolver::collect_data(collection& facts)
    {
        // Default to the base implementation
        data result = posix::operating_system_resolver::collect_data(facts);

        each_line("/usr/bin/sw_vers", [&](string& line) {
            // Split at the first ':'
            auto pos = line.find(':');
            if (pos == string::npos) {
                return true;
            }
            string key = line.substr(0, pos);
            boost::trim(key);
            string value = line.substr(pos + 1);
            boost::trim(value);

            if (key == "ProductName") {
                result.osx.product = move(value);
            } else if (key == "BuildVersion") {
                result.osx.build = move(value);
            } else if (key == "ProductVersion") {
                result.osx.version = move(value);
            }

            // Continue only if we haven't populated the data
            return result.osx.product.empty() || result.osx.build.empty() || result.osx.version.empty();
        });

        // If osx.build is missing the patch version, add '.0'
        if (boost::regex_match(result.osx.version, boost::regex("^\\d+\\.\\d+$"))) {
            result.osx.version += ".0";
        }

        return result;
    }

}}}  // namespace facter::facts::osx

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
facter-3.12.2.cfacter.20181217 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.12.1.cfacter.20181031 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.11.6.cfacter.20181031 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.12.1.cfacter.20181023 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.11.5.cfacter.20181022 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.12.0.cfacter.20181004 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.12.0.cfacter.20181001 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.12.0.cfacter.20180918 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.11.4.cfacter.20180821 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.11.3.cfacter.20180716 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.11.2.cfacter.20180612 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.9.6.cfacter.20180612 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.11.2.cfacter.20180606 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.9.6.cfacter.20180606 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
facter-3.11.0.cfacter.20180319 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc
cfacter-3.11.0.rc.20180314 ext/facter/facter/lib/src/facts/osx/operating_system_resolver.cc