mirror of
https://github.com/hashicorp/packer.git
synced 2026-02-05 12:45:10 +01:00
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.
This commit is contained in:
committed by
Lucas Bajolet
parent
7823a40a25
commit
2d8aa69779
@@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user