From 2d8aa69779fbbc9225515a90bea84e096b0882a2 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Mon, 29 Apr 2024 16:09:57 -0400 Subject: [PATCH] init: fix --force and pre-releases installed case When packer init is invoked with a --force argument, but no --update, we clamp the version to install based on the last one locally installed. Doing this may however cause the constraint to always be false if the latest available version of a plugin is a pre-release, as none of the upstream constraints will match that. Therefore this commit changes how the constraint is derived from the local list of installations, so that only the last installation that matches the original constraint will be used, and not a pre-release. --- command/init.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/command/init.go b/command/init.go index 2d8a19377..100549174 100644 --- a/command/init.go +++ b/command/init.go @@ -127,7 +127,20 @@ for more info.`) } if cla.Force && !cla.Upgrade { - pluginRequirement.VersionConstraints, _ = gversion.NewConstraint(fmt.Sprintf("=%s", installs[len(installs)-1].Version)) + // Only place another constaint to the latest release + // binary, if any, otherwise this is essentially the same + // as an upgrade + var installVersion string + for _, install := range installs { + ver, _ := gversion.NewVersion(install.Version) + if ver.Prerelease() == "" { + installVersion = install.Version + } + } + + if installVersion != "" { + pluginRequirement.VersionConstraints, _ = gversion.NewConstraint(fmt.Sprintf("=%s", installVersion)) + } } }