fix 2260: fallback serial to Board (#2263)

This commit is contained in:
Edouard Vanbelle 2024-07-15 14:43:50 +02:00 committed by GitHub
parent 47752e1573
commit d5ba2ef6ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,6 +8,7 @@ import (
"context" "context"
"os" "os"
"os/exec" "os/exec"
"regexp"
"runtime" "runtime"
"strings" "strings"
"time" "time"
@ -89,9 +90,17 @@ func _getInfo() string {
func sysInfo() (serialNumber string, productName string, manufacturer string) { func sysInfo() (serialNumber string, productName string, manufacturer string) {
var si sysinfo.SysInfo var si sysinfo.SysInfo
si.GetSysInfo() si.GetSysInfo()
isascii := regexp.MustCompile("^[[:ascii:]]+$")
serial := si.Chassis.Serial serial := si.Chassis.Serial
if (serial == "Default string" || serial == "") && si.Product.Serial != "" { if (serial == "Default string" || serial == "") && si.Product.Serial != "" {
serial = si.Product.Serial serial = si.Product.Serial
} }
return serial, si.Product.Name, si.Product.Vendor if (!isascii.MatchString(serial)) && si.Board.Serial != "" {
serial = si.Board.Serial
}
name := si.Product.Name
if (!isascii.MatchString(name)) && si.Board.Name != "" {
name = si.Board.Name
}
return serial, name, si.Product.Vendor
} }