forked from TrueCloudLab/restic
backup: Reenable JSON status updates with redirected output
After the refactoring status updates were no longer printed in quiet mode or when the output is not an interactive terminal. However, the JSON output is often piped to e.g. another program. Thus, don't set the update frequency to 0 in that case. The status updates are still disabled for backup --quiet. This also reduces the status update frequency to 60fps compared to a potentially much higher value before the refactoring.
This commit is contained in:
parent
d62bfed65d
commit
a144c986f2
2 changed files with 4 additions and 4 deletions
|
@ -547,7 +547,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina
|
||||||
}()
|
}()
|
||||||
gopts.stdout, gopts.stderr = progressPrinter.Stdout(), progressPrinter.Stderr()
|
gopts.stdout, gopts.stderr = progressPrinter.Stdout(), progressPrinter.Stderr()
|
||||||
|
|
||||||
progressReporter.SetMinUpdatePause(calculateProgressInterval(!gopts.Quiet))
|
progressReporter.SetMinUpdatePause(calculateProgressInterval(!gopts.Quiet, gopts.JSON))
|
||||||
|
|
||||||
t.Go(func() error { return progressReporter.Run(t.Context(gopts.ctx)) })
|
t.Go(func() error { return progressReporter.Run(t.Context(gopts.ctx)) })
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
// calculateProgressInterval returns the interval configured via RESTIC_PROGRESS_FPS
|
// calculateProgressInterval returns the interval configured via RESTIC_PROGRESS_FPS
|
||||||
// or if unset returns an interval for 60fps on interactive terminals and 0 (=disabled)
|
// or if unset returns an interval for 60fps on interactive terminals and 0 (=disabled)
|
||||||
// for non-interactive terminals or when run using the --quiet flag
|
// for non-interactive terminals or when run using the --quiet flag
|
||||||
func calculateProgressInterval(show bool) time.Duration {
|
func calculateProgressInterval(show bool, json bool) time.Duration {
|
||||||
interval := time.Second / 60
|
interval := time.Second / 60
|
||||||
fps, err := strconv.ParseFloat(os.Getenv("RESTIC_PROGRESS_FPS"), 64)
|
fps, err := strconv.ParseFloat(os.Getenv("RESTIC_PROGRESS_FPS"), 64)
|
||||||
if err == nil && fps > 0 {
|
if err == nil && fps > 0 {
|
||||||
|
@ -22,7 +22,7 @@ func calculateProgressInterval(show bool) time.Duration {
|
||||||
fps = 60
|
fps = 60
|
||||||
}
|
}
|
||||||
interval = time.Duration(float64(time.Second) / fps)
|
interval = time.Duration(float64(time.Second) / fps)
|
||||||
} else if !stdoutCanUpdateStatus() || !show {
|
} else if !json && !stdoutCanUpdateStatus() || !show {
|
||||||
interval = 0
|
interval = 0
|
||||||
}
|
}
|
||||||
return interval
|
return interval
|
||||||
|
@ -33,7 +33,7 @@ func newProgressMax(show bool, max uint64, description string) *progress.Counter
|
||||||
if !show {
|
if !show {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
interval := calculateProgressInterval(show)
|
interval := calculateProgressInterval(show, false)
|
||||||
canUpdateStatus := stdoutCanUpdateStatus()
|
canUpdateStatus := stdoutCanUpdateStatus()
|
||||||
|
|
||||||
return progress.New(interval, max, func(v uint64, max uint64, d time.Duration, final bool) {
|
return progress.New(interval, max, func(v uint64, max uint64, d time.Duration, final bool) {
|
||||||
|
|
Loading…
Reference in a new issue