ui: force backup progress update on signal

This commit is contained in:
Michael Eischer 2020-12-29 15:21:16 +01:00
parent 34afc93ddc
commit 92da5168e1
1 changed files with 7 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/restic/restic/internal/archiver" "github.com/restic/restic/internal/archiver"
"github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/restic"
"github.com/restic/restic/internal/ui/signals"
"github.com/restic/restic/internal/ui/termstatus" "github.com/restic/restic/internal/ui/termstatus"
) )
@ -87,6 +88,7 @@ func (b *Backup) Run(ctx context.Context) error {
) )
t := time.NewTicker(time.Second) t := time.NewTicker(time.Second)
signalsCh := signals.GetProgressChannel()
defer t.Stop() defer t.Stop()
defer close(b.closed) defer close(b.closed)
// Reset status when finished // Reset status when finished
@ -97,6 +99,8 @@ func (b *Backup) Run(ctx context.Context) error {
}() }()
for { for {
forceUpdate := false
select { select {
case <-ctx.Done(): case <-ctx.Done():
return nil return nil
@ -133,10 +137,12 @@ func (b *Backup) Run(ctx context.Context) error {
todo := float64(total.Bytes - processed.Bytes) todo := float64(total.Bytes - processed.Bytes)
secondsRemaining = uint64(secs / float64(processed.Bytes) * todo) secondsRemaining = uint64(secs / float64(processed.Bytes) * todo)
} }
case <-signalsCh:
forceUpdate = true
} }
// limit update frequency // limit update frequency
if time.Since(lastUpdate) < b.MinUpdatePause || b.MinUpdatePause == 0 { if !forceUpdate && (time.Since(lastUpdate) < b.MinUpdatePause || b.MinUpdatePause == 0) {
continue continue
} }
lastUpdate = time.Now() lastUpdate = time.Now()