version: fix reported os/kernel version for windows

This commit is contained in:
albertony 2023-04-09 14:16:25 +02:00
parent 52fbb10b47
commit bdfe213c47

View File

@ -1,7 +1,6 @@
package buildinfo
import (
"fmt"
"regexp"
"strings"
"unsafe"
@ -32,10 +31,10 @@ func GetOSVersion() (osVersion, osKernel string) {
}
}
// Simplify kernel output: `RELEASE.BUILD Build BUILD` -> `RELEASE.BUILD`
match := regexp.MustCompile(`^([\d\.]+?\.)(\d+) Build (\d+)$`).FindStringSubmatch(osKernel)
// Simplify kernel output: `MAJOR.MINOR.BUILD.REVISION Build BUILD.REVISION` -> `MAJOR.MINOR.BUILD.REVISION`
match := regexp.MustCompile(`^(\d+\.\d+\.(\d+\.\d+)) Build (\d+\.\d+)$`).FindStringSubmatch(osKernel)
if len(match) == 4 && match[2] == match[3] {
osKernel = match[1] + match[2]
osKernel = match[1]
}
}
@ -53,11 +52,6 @@ func GetOSVersion() (osVersion, osKernel string) {
}
}
updateRevision := getRegistryVersionInt("UBR")
if osKernel != "" && updateRevision != 0 {
osKernel += fmt.Sprintf(".%d", updateRevision)
}
if arch, err := host.KernelArch(); err == nil && arch != "" {
if strings.HasSuffix(arch, "64") && osVersion != "" {
osVersion += " (64 bit)"