From 4437f8d8bad30b5cff5c42eef09dda6f1a6368bc Mon Sep 17 00:00:00 2001 From: Ed Maxwell-Lyte <2248005+edwardmlyte@users.noreply.github.com> Date: Wed, 9 Jan 2019 16:22:33 +0000 Subject: [PATCH] Use go-version for comparison --- builder/virtualbox/common/driver_4_2.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/builder/virtualbox/common/driver_4_2.go b/builder/virtualbox/common/driver_4_2.go index 6dddd3689..20de72c00 100644 --- a/builder/virtualbox/common/driver_4_2.go +++ b/builder/virtualbox/common/driver_4_2.go @@ -3,6 +3,7 @@ package common import ( "bytes" "fmt" + "github.com/hashicorp/go-version" "log" "os/exec" "regexp" @@ -26,10 +27,17 @@ func (d *VBox42Driver) CreateSATAController(vmName string, name string, portcoun portCountArg := "--portcount" - for _, prefix := range [7]string{"0.", "1.", "2.", "3.", "4.0", "4.1", "4.2"} { - if strings.HasPrefix(version, prefix) { - portCountArg = "--sataportcount" - } + currentVersion, err := version.NewVersion(version) + if err != nil { + return err + } + versionUsingPortCount, err := version.NewVersion("4.3") + if err != nil { + return err + } + + if currentVersion.LessThan(versionUsingPortCount) { + portCountArg = "--sataportcount" } command := []string{