Fix FindMinSnapshotByGeneration() loop ref bug

This commit is contained in:
Ben Johnson
2021-12-05 09:39:14 -07:00
parent 1e6878998c
commit 393317b6f8
2 changed files with 14 additions and 2 deletions

View File

@@ -207,11 +207,13 @@ func FilterSnapshotsAfter(a []SnapshotInfo, t time.Time) []SnapshotInfo {
// FindMinSnapshotByGeneration finds the snapshot with the lowest index in a generation.
func FindMinSnapshotByGeneration(a []SnapshotInfo, generation string) *SnapshotInfo {
var min *SnapshotInfo
for _, snapshot := range a {
for i := range a {
snapshot := &a[i]
if snapshot.Generation != generation {
continue
} else if min == nil || snapshot.Index < min.Index {
min = &snapshot
min = snapshot
}
}
return min