Skip to content

Commit

Permalink
printer: dedup warnings
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Jun 25, 2024
1 parent 77d093d commit 693fda3
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion util/progress/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package progress

import (
"context"
"crypto/sha256"
"encoding/hex"
"os"
"sync"

Expand Down Expand Up @@ -58,7 +60,7 @@ func (p *Printer) Write(s *client.SolveStatus) {
}

func (p *Printer) Warnings() []client.VertexWarning {
return p.warnings
return dedupWarnings(p.warnings)
}

func (p *Printer) ValidateLogSource(dgst digest.Digest, v interface{}) bool {
Expand Down Expand Up @@ -184,3 +186,36 @@ func WithOnClose(onclose func()) PrinterOpt {
opt.onclose = onclose
}
}

func dedupWarnings(inp []client.VertexWarning) []client.VertexWarning {
m := make(map[string]client.VertexWarning)
for _, w := range inp {
h := sha256.New()
h.Write(w.Short)
h.Write([]byte{0})
for _, d := range w.Detail {
h.Write(d)
h.Write([]byte{0})
}
h.Write([]byte(w.URL))
h.Write([]byte{0})
for _, r := range w.Range {
h.Write([]byte(r.String()))
h.Write([]byte{0})
}
if w.SourceInfo != nil {
h.Write([]byte(w.SourceInfo.Filename))
h.Write([]byte(w.SourceInfo.Data))
}
h.Write([]byte{0})
hkey := hex.EncodeToString(h.Sum(nil))
if _, ok := m[hkey]; !ok {
m[hkey] = w
}
}
res := make([]client.VertexWarning, 0, len(m))
for _, w := range m {
res = append(res, w)
}
return res
}

0 comments on commit 693fda3

Please sign in to comment.