providercache: actually break out of the loop when a matching version is found (#24823)

This commit is contained in:
Kristin Laemmert 2020-05-01 08:49:47 -04:00 committed by GitHub
parent ce03f1255f
commit cca0526705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -554,7 +554,9 @@ func (err InstallerError) Error() string {
func (i *Installer) findClosestProtocolCompatibleVersion(provider addrs.Provider, version versions.Version) versions.Version {
var match versions.Version
available, _ := i.source.AvailableVersions(provider)
available.Sort() // put the versions in increasing order of precedence
available.Sort()
// put the versions in increasing order of precedence
FindMatch:
for index := len(available) - 1; index >= 0; index-- { // walk backwards to consider newer versions first
meta, _ := i.source.PackageMeta(provider, available[index], i.targetDir.targetPlatform)
if len(meta.ProtocolVersions) > 0 {
@ -562,10 +564,11 @@ func (i *Installer) findClosestProtocolCompatibleVersion(provider addrs.Provider
for _, version := range meta.ProtocolVersions {
if protoVersions.Has(version) {
match = available[index]
break // we will only consider the newest matching version
break FindMatch // we will only consider the newest matching version
}
}
}
}
return match
}