From 346f5d9bbab22c976e8b2e6d6d30acb094c512c2 Mon Sep 17 00:00:00 2001 From: Ed Maxwell-Lyte <2248005+edwardmlyte@users.noreply.github.com> Date: Wed, 9 Jan 2019 08:45:01 +0000 Subject: [PATCH 1/3] Simplify version check for port count argument Might be personal preference, but I think this reads more clearly --- builder/virtualbox/common/driver_4_2.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/builder/virtualbox/common/driver_4_2.go b/builder/virtualbox/common/driver_4_2.go index 1a2c8541d..6dddd3689 100644 --- a/builder/virtualbox/common/driver_4_2.go +++ b/builder/virtualbox/common/driver_4_2.go @@ -25,10 +25,11 @@ func (d *VBox42Driver) CreateSATAController(vmName string, name string, portcoun } portCountArg := "--portcount" - if strings.HasPrefix(version, "0.") || strings.HasPrefix(version, "1.") || strings.HasPrefix(version, "2.") || - strings.HasPrefix(version, "3.") || strings.HasPrefix(version, "4.0") || strings.HasPrefix(version, "4.1") || - strings.HasPrefix(version, "4.2") { - portCountArg = "--sataportcount" + + for _, prefix := range [7]string{"0.", "1.", "2.", "3.", "4.0", "4.1", "4.2"} { + if strings.HasPrefix(version, prefix) { + portCountArg = "--sataportcount" + } } command := []string{ 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 2/3] 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{ From e8e92fe6c604425cafd71c3dba93a64fdfad6785 Mon Sep 17 00:00:00 2001 From: Ed Maxwell-Lyte <2248005+edwardmlyte@users.noreply.github.com> Date: Wed, 9 Jan 2019 16:30:54 +0000 Subject: [PATCH 3/3] rename clashing import --- builder/virtualbox/common/driver_4_2.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/builder/virtualbox/common/driver_4_2.go b/builder/virtualbox/common/driver_4_2.go index 20de72c00..8b6402c3a 100644 --- a/builder/virtualbox/common/driver_4_2.go +++ b/builder/virtualbox/common/driver_4_2.go @@ -3,7 +3,7 @@ package common import ( "bytes" "fmt" - "github.com/hashicorp/go-version" + versionUtil "github.com/hashicorp/go-version" "log" "os/exec" "regexp" @@ -27,16 +27,16 @@ func (d *VBox42Driver) CreateSATAController(vmName string, name string, portcoun portCountArg := "--portcount" - currentVersion, err := version.NewVersion(version) + currentVersion, err := versionUtil.NewVersion(version) if err != nil { return err } - versionUsingPortCount, err := version.NewVersion("4.3") + firstVersionUsingPortCount, err := versionUtil.NewVersion("4.3") if err != nil { return err } - if currentVersion.LessThan(versionUsingPortCount) { + if currentVersion.LessThan(firstVersionUsingPortCount) { portCountArg = "--sataportcount" }