From eab8d8ca0b3a33db13c7ca0cdfbc4ddf313eb65f Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Tue, 23 Apr 2024 15:17:04 -0400 Subject: [PATCH] packer: remove duplicate version variable 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. --- packer/plugin-getter/plugins.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packer/plugin-getter/plugins.go b/packer/plugin-getter/plugins.go index 0a5518a375b..982832b8363 100644 --- a/packer/plugin-getter/plugins.go +++ b/packer/plugin-getter/plugins.go @@ -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 } @@ -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 }