From cca0526705fab1c875471c60a6e8aaea2a9e443d Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Fri, 1 May 2020 08:49:47 -0400 Subject: [PATCH] providercache: actually break out of the loop when a matching version is found (#24823) --- internal/providercache/installer.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/providercache/installer.go b/internal/providercache/installer.go index 1f446cd49..4a3ee47c7 100644 --- a/internal/providercache/installer.go +++ b/internal/providercache/installer.go @@ -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 }