better handling of version/patch especiallly for snapshots, use updateWorkDir
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"io/ioutil"
|
||||
"golang.org/x/net/route"
|
||||
@@ -190,34 +189,17 @@ func getArch() (string, error) {
|
||||
|
||||
func getFreeBSDVersion() (FreeBSDVersion, error) {
|
||||
var version FreeBSDVersion
|
||||
regex := `([0-9]{1,2})(\.)?([0-9]{1,2})?\-([^\-]*)(\-)?(p[0-9]{1,2})?`
|
||||
|
||||
re := regexp.MustCompile(regex)
|
||||
|
||||
out, err := executeCommand("/bin/freebsd-version")
|
||||
if err != nil {
|
||||
return version, fmt.Errorf("Error executing \"/bin/freebsd-version\": %v", err)
|
||||
}
|
||||
|
||||
if re.MatchString(out) {
|
||||
version.major, err = strconv.Atoi(re.FindStringSubmatch(out)[1])
|
||||
if err != nil {
|
||||
return version, err
|
||||
}
|
||||
version.minor, err = strconv.Atoi(re.FindStringSubmatch(out)[3])
|
||||
if err != nil {
|
||||
return version, err
|
||||
}
|
||||
version.flavor = strings.Trim(re.FindStringSubmatch(out)[4], "\n")
|
||||
|
||||
// Skip the 'p' starting patch level
|
||||
if len(re.FindStringSubmatch(out)[6]) > 0 {
|
||||
version.patchLevel, err = strconv.Atoi(re.FindStringSubmatch(out)[6][1:])
|
||||
if err != nil {
|
||||
return version, err
|
||||
}
|
||||
}
|
||||
version, err = freebsdVersionToStruct(out)
|
||||
if err != nil {
|
||||
return version, err
|
||||
}
|
||||
|
||||
return version, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user