Skip to content

Commit

Permalink
packer: remove duplicate version variable
Browse files Browse the repository at this point in the history
When listing installed plugins, we check that the plugin's reported
version through describe matches what's in the name of the file.

Doing do, we were parsing the same version string twice without
modifying it, which was not necessary, so this commit changes that.
  • Loading branch information
lbajolet-hashicorp committed Apr 23, 2024
1 parent 2af829a commit eab8d8c
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions packer/plugin-getter/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,13 @@ func (pr Requirement) ListInstallations(opts ListInstallationsOptions) (InstallL
continue
}

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

descVersion, err := goversion.NewVersion(describeInfo.Version)
if err != nil {
log.Printf("malformed reported version string %q: %s, ignoring", describeInfo.Version, err)
continue
}

if rawVersion.Compare(descVersion) != 0 {
if ver.Compare(descVersion) != 0 {
log.Printf("plugin %q reported version %q while its name implies version %q, ignoring", path, describeInfo.Version, pluginVersionStr)
continue
}
Expand All @@ -225,7 +219,7 @@ func (pr Requirement) ListInstallations(opts ListInstallationsOptions) (InstallL
// Note: we use the raw version name here, without the pre-release
// suffix, as otherwise constraints reject them, which is not
// what we want by default.
if !pr.VersionConstraints.Check(rawVersion.Core()) {
if !pr.VersionConstraints.Check(ver.Core()) {
log.Printf("[TRACE] version %q of file %q does not match constraint %q", pluginVersionStr, path, pr.VersionConstraints.String())
continue
}
Expand Down

0 comments on commit eab8d8c

Please sign in to comment.