func getOSInfo()

in providers/darwin/os_darwin.go [48:94]


func getOSInfo(data []byte) (*types.OSInfo, error) {
	attrs := map[string]string{}
	if _, err := plist.Unmarshal(data, &attrs); err != nil {
		return nil, fmt.Errorf("failed to unmarshal plist data: %w", err)
	}

	productName, found := attrs[plistProductName]
	if !found {
		return nil, fmt.Errorf("plist key %v not found", plistProductName)
	}

	version, found := attrs[plistProductVersion]
	if !found {
		return nil, fmt.Errorf("plist key %v not found", plistProductVersion)
	}

	build, found := attrs[plistProductBuildVersion]
	if !found {
		return nil, fmt.Errorf("plist key %v not found", plistProductBuildVersion)
	}

	var major, minor, patch int
	for i, v := range strings.SplitN(version, ".", 3) {
		switch i {
		case 0:
			major, _ = strconv.Atoi(v)
		case 1:
			minor, _ = strconv.Atoi(v)
		case 2:
			patch, _ = strconv.Atoi(v)
		default:
			break
		}
	}

	return &types.OSInfo{
		Type:     "macos",
		Family:   "darwin",
		Platform: "darwin",
		Name:     productName,
		Version:  version,
		Major:    major,
		Minor:    minor,
		Patch:    patch,
		Build:    build,
	}, nil
}