From f6a27a664b9cdfea0fdb20d5480579213c512e01 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:27:03 +0200 Subject: [PATCH] ls: ensure deterministic output for truncated platforms Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- commands/ls.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/commands/ls.go b/commands/ls.go index da2bb801..33a84f29 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -308,6 +308,12 @@ func (tp truncatedPlatforms) String() string { var out []string var count int + var keys []string + for k := range tp.res { + keys = append(keys, k) + } + sort.Strings(keys) + seen := make(map[string]struct{}) for _, mpf := range truncMajorPlatforms { if tpf, ok := tp.res[mpf]; ok { @@ -333,19 +339,19 @@ func (tp truncatedPlatforms) String() string { } } - for mpf, pf := range tp.res { + for _, mpf := range keys { if len(out) >= tp.max { break } if _, ok := seen[mpf]; ok { continue } - if len(pf) == 1 { - out = append(out, fmt.Sprintf("%s", pf[0])) + if len(tp.res[mpf]) == 1 { + out = append(out, fmt.Sprintf("%s", tp.res[mpf][0])) count++ } else { hasPreferredPlatform := false - for _, pf := range pf { + for _, pf := range tp.res[mpf] { if strings.HasSuffix(pf, "*") { hasPreferredPlatform = true break @@ -355,8 +361,8 @@ func (tp truncatedPlatforms) String() string { if hasPreferredPlatform { mainpf += "*" } - out = append(out, fmt.Sprintf("%s (+%d)", mainpf, len(pf))) - count += len(pf) + out = append(out, fmt.Sprintf("%s (+%d)", mainpf, len(tp.res[mpf]))) + count += len(tp.res[mpf]) } }