mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00

No other parts of the progress rendering modify the inputs, so we should avoid this as well. This actually fixes an edge case in pushWithMoby which writes the same VertexStatus multiple times, modifying the timestamps and similar. However, if the operation takes long enough the small time difference can accumulate, and move the Start time far into the past. Signed-off-by: Justin Chadwell <me@jedevc.com>
79 lines
1.5 KiB
Go
79 lines
1.5 KiB
Go
package progress
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/moby/buildkit/client"
|
|
)
|
|
|
|
func ResetTime(in Writer) Writer {
|
|
return &pw{Writer: in, status: make(chan *client.SolveStatus), tm: time.Now()}
|
|
}
|
|
|
|
func (w *pw) Write(st *client.SolveStatus) {
|
|
if w.diff == nil {
|
|
for _, v := range st.Vertexes {
|
|
if v.Started != nil {
|
|
d := v.Started.Sub(w.tm)
|
|
w.diff = &d
|
|
}
|
|
}
|
|
}
|
|
if w.diff != nil {
|
|
vertexes := make([]*client.Vertex, 0, len(st.Vertexes))
|
|
for _, v := range st.Vertexes {
|
|
v := *v
|
|
if v.Started != nil {
|
|
d := v.Started.Add(-*w.diff)
|
|
v.Started = &d
|
|
}
|
|
if v.Completed != nil {
|
|
d := v.Completed.Add(-*w.diff)
|
|
v.Completed = &d
|
|
}
|
|
vertexes = append(vertexes, &v)
|
|
}
|
|
|
|
statuses := make([]*client.VertexStatus, 0, len(st.Statuses))
|
|
for _, v := range st.Statuses {
|
|
v := *v
|
|
if v.Started != nil {
|
|
d := v.Started.Add(-*w.diff)
|
|
v.Started = &d
|
|
}
|
|
if v.Completed != nil {
|
|
d := v.Completed.Add(-*w.diff)
|
|
v.Completed = &d
|
|
}
|
|
v.Timestamp = v.Timestamp.Add(-*w.diff)
|
|
statuses = append(statuses, &v)
|
|
}
|
|
|
|
logs := make([]*client.VertexLog, 0, len(st.Logs))
|
|
for _, v := range st.Logs {
|
|
v := *v
|
|
v.Timestamp = v.Timestamp.Add(-*w.diff)
|
|
logs = append(logs, &v)
|
|
}
|
|
|
|
st = &client.SolveStatus{
|
|
Vertexes: vertexes,
|
|
Statuses: statuses,
|
|
Logs: logs,
|
|
Warnings: st.Warnings,
|
|
}
|
|
}
|
|
w.Writer.Write(st)
|
|
}
|
|
|
|
type pw struct {
|
|
Writer
|
|
tm time.Time
|
|
diff *time.Duration
|
|
status chan *client.SolveStatus
|
|
}
|
|
|
|
func (w *pw) Status() chan *client.SolveStatus {
|
|
return w.status
|
|
}
|