engine: resources: nspawn: Trim possible systemd version suffix

This commit is contained in:
Jan Martens
2019-05-14 15:57:32 +02:00
parent 38dfaa1caa
commit 3c1da423fa

View File

@@ -21,6 +21,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
"strings"
"unicode" "unicode"
"github.com/purpleidea/mgmt/engine" "github.com/purpleidea/mgmt/engine"
@@ -358,10 +359,12 @@ func systemdVersion() (uint16, error) {
return 0, errwrap.Wrapf(err, "could not get version property") return 0, errwrap.Wrapf(err, "could not get version property")
} }
// lose the surrounding quotes // lose the surrounding quotes
verNum, err := strconv.Unquote(verString) verNumString, err := strconv.Unquote(verString)
if err != nil { if err != nil {
return 0, errwrap.Wrapf(err, "error unquoting version number") return 0, errwrap.Wrapf(err, "error unquoting version number")
} }
// trim possible version suffix like in "242.19-1"
verNum := strings.Split(verNumString, ".")[0]
// cast to uint16 // cast to uint16
ver, err := strconv.ParseUint(verNum, 10, 16) ver, err := strconv.ParseUint(verNum, 10, 16)
if err != nil { if err != nil {