Skip to content

Commit

Permalink
packer: alias version as goversion for getter
Browse files Browse the repository at this point in the history
Since we named the version from the getter `version', this means we have
a naming conflict inside the loop that attempts to install a versioned
candidate for a plugin, making it impossible to invoke something from
the go-version package.

Since we'll introduce a change that needs the latter capability, we must
either rename the local variable to something else than `version', or we
need to alias the package locally.

This commit implements the latter, opting to call the package goversion.
  • Loading branch information
lbajolet-hashicorp committed Apr 12, 2024
1 parent d1a45ce commit a33b220
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packer/plugin-getter/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-version"
goversion "github.com/hashicorp/go-version"
pluginsdk "github.com/hashicorp/packer-plugin-sdk/plugin"
"github.com/hashicorp/packer-plugin-sdk/tmp"
"github.com/hashicorp/packer/hcl2template/addrs"
Expand All @@ -46,7 +46,7 @@ type Requirement struct {

// VersionConstraints as defined by user. Empty ( to be avoided ) means
// highest found version.
VersionConstraints version.Constraints
VersionConstraints goversion.Constraints
}

type BinaryInstallationOptions struct {
Expand Down Expand Up @@ -174,7 +174,7 @@ func (pr Requirement) ListInstallations(opts ListInstallationsOptions) (InstallL
// versionsStr now looks like v1.2.3_x5.1 or amazon_v1.2.3_x5.1
parts := strings.SplitN(versionsStr, "_", 2)
pluginVersionStr, protocolVersionStr := parts[0], parts[1]
ver, err := version.NewVersion(pluginVersionStr)
ver, err := goversion.NewVersion(pluginVersionStr)
if err != nil {
// could not be parsed, ignoring the file
log.Printf("found %q with an incorrect %q version, ignoring it. %v", path, pluginVersionStr, err)
Expand All @@ -191,13 +191,13 @@ func (pr Requirement) ListInstallations(opts ListInstallationsOptions) (InstallL
continue
}

rawVersion, err := version.NewVersion(pluginVersionStr)
rawVersion, err := goversion.NewVersion(pluginVersionStr)
if err != nil {
log.Printf("malformed version string in filename %q: %s, ignoring", pluginVersionStr, err)
continue
}

descVersion, err := version.NewVersion(describeInfo.Version)
descVersion, err := goversion.NewVersion(describeInfo.Version)
if err != nil {
log.Printf("malformed reported version string %q: %s, ignoring", describeInfo.Version, err)
continue
Expand Down Expand Up @@ -365,7 +365,7 @@ type GetOptions struct {

BinaryInstallationOptions

version *version.Version
version *goversion.Version

expectedZipFilename string
}
Expand Down Expand Up @@ -568,7 +568,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
getters := opts.Getters

log.Printf("[TRACE] getting available versions for the %s plugin", pr.Identifier)
versions := version.Collection{}
versions := goversion.Collection{}
var errs *multierror.Error
for _, getter := range getters {

Expand Down Expand Up @@ -596,7 +596,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
continue
}
for _, release := range releases {
v, err := version.NewVersion(release.Version)
v, err := goversion.NewVersion(release.Version)
if err != nil {
err := fmt.Errorf("could not parse release version %s. %w", release.Version, err)
errs = multierror.Append(errs, err)
Expand Down

0 comments on commit a33b220

Please sign in to comment.