mirror of https://github.com/docker/docs.git
Merge pull request #18680 from aaronlehmann/duplicate-pull-complete-message
Avoid outputting last progress item twice
This commit is contained in:
commit
bce70cdc2c
|
@ -124,7 +124,6 @@ func (t *transfer) Broadcast(masterProgressChan <-chan progress.Progress) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
t.broadcastDone = true
|
t.broadcastDone = true
|
||||||
}
|
}
|
||||||
|
@ -159,18 +158,23 @@ func (t *transfer) Watch(progressOutput progress.Output) *Watcher {
|
||||||
defer func() {
|
defer func() {
|
||||||
close(w.running)
|
close(w.running)
|
||||||
}()
|
}()
|
||||||
done := false
|
var (
|
||||||
|
done bool
|
||||||
|
lastWritten progress.Progress
|
||||||
|
hasLastWritten bool
|
||||||
|
)
|
||||||
for {
|
for {
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
hasLastProgress := t.hasLastProgress
|
hasLastProgress := t.hasLastProgress
|
||||||
lastProgress := t.lastProgress
|
lastProgress := t.lastProgress
|
||||||
t.mu.Unlock()
|
t.mu.Unlock()
|
||||||
|
|
||||||
// This might write the last progress item a
|
// Make sure we don't write the last progress item
|
||||||
// second time (since channel closure also gets
|
// twice.
|
||||||
// us here), but that's fine.
|
if hasLastProgress && (!done || !hasLastWritten || lastProgress != lastWritten) {
|
||||||
if hasLastProgress {
|
|
||||||
progressOutput.WriteProgress(lastProgress)
|
progressOutput.WriteProgress(lastProgress)
|
||||||
|
lastWritten = lastProgress
|
||||||
|
hasLastWritten = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if done {
|
if done {
|
||||||
|
|
|
@ -41,15 +41,6 @@ func TestTransfer(t *testing.T) {
|
||||||
if p.Current != 0 {
|
if p.Current != 0 {
|
||||||
t.Fatalf("got unexpected progress value: %d (expected 0)", p.Current)
|
t.Fatalf("got unexpected progress value: %d (expected 0)", p.Current)
|
||||||
}
|
}
|
||||||
} else if p.Current == 10 {
|
|
||||||
// Special case: last progress output may be
|
|
||||||
// repeated because the transfer finishing
|
|
||||||
// causes the latest progress output to be
|
|
||||||
// written to the channel (in case the watcher
|
|
||||||
// missed it).
|
|
||||||
if p.Current != 9 && p.Current != 10 {
|
|
||||||
t.Fatalf("got unexpected progress value: %d (expected %d)", p.Current, val+1)
|
|
||||||
}
|
|
||||||
} else if p.Current != val+1 {
|
} else if p.Current != val+1 {
|
||||||
t.Fatalf("got unexpected progress value: %d (expected %d)", p.Current, val+1)
|
t.Fatalf("got unexpected progress value: %d (expected %d)", p.Current, val+1)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue