Merge pull request #18680 from aaronlehmann/duplicate-pull-complete-message
Avoid outputting last progress item twice
This commit is contained in:
commit
bce70cdc2c
2 changed files with 10 additions and 15 deletions
|
@ -124,7 +124,6 @@ func (t *transfer) Broadcast(masterProgressChan <-chan progress.Progress) {
|
|||
default:
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
t.broadcastDone = true
|
||||
}
|
||||
|
@ -159,18 +158,23 @@ func (t *transfer) Watch(progressOutput progress.Output) *Watcher {
|
|||
defer func() {
|
||||
close(w.running)
|
||||
}()
|
||||
done := false
|
||||
var (
|
||||
done bool
|
||||
lastWritten progress.Progress
|
||||
hasLastWritten bool
|
||||
)
|
||||
for {
|
||||
t.mu.Lock()
|
||||
hasLastProgress := t.hasLastProgress
|
||||
lastProgress := t.lastProgress
|
||||
t.mu.Unlock()
|
||||
|
||||
// This might write the last progress item a
|
||||
// second time (since channel closure also gets
|
||||
// us here), but that's fine.
|
||||
if hasLastProgress {
|
||||
// Make sure we don't write the last progress item
|
||||
// twice.
|
||||
if hasLastProgress && (!done || !hasLastWritten || lastProgress != lastWritten) {
|
||||
progressOutput.WriteProgress(lastProgress)
|
||||
lastWritten = lastProgress
|
||||
hasLastWritten = true
|
||||
}
|
||||
|
||||
if done {
|
||||
|
|
|
@ -41,15 +41,6 @@ func TestTransfer(t *testing.T) {
|
|||
if p.Current != 0 {
|
||||
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 {
|
||||
t.Fatalf("got unexpected progress value: %d (expected %d)", p.Current, val+1)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue