From a144c986f23e75387f1ac8e543c4653a6df1381b Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Wed, 18 Aug 2021 13:03:25 +0200 Subject: [PATCH] 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. --- cmd/restic/cmd_backup.go | 2 +- cmd/restic/progress.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index d4ec3c288..037b61103 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -547,7 +547,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina }() 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)) }) diff --git a/cmd/restic/progress.go b/cmd/restic/progress.go index 26a694c25..5a77bc6ee 100644 --- a/cmd/restic/progress.go +++ b/cmd/restic/progress.go @@ -14,7 +14,7 @@ import ( // calculateProgressInterval returns the interval configured via RESTIC_PROGRESS_FPS // 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 -func calculateProgressInterval(show bool) time.Duration { +func calculateProgressInterval(show bool, json bool) time.Duration { interval := time.Second / 60 fps, err := strconv.ParseFloat(os.Getenv("RESTIC_PROGRESS_FPS"), 64) if err == nil && fps > 0 { @@ -22,7 +22,7 @@ func calculateProgressInterval(show bool) time.Duration { fps = 60 } interval = time.Duration(float64(time.Second) / fps) - } else if !stdoutCanUpdateStatus() || !show { + } else if !json && !stdoutCanUpdateStatus() || !show { interval = 0 } return interval @@ -33,7 +33,7 @@ func newProgressMax(show bool, max uint64, description string) *progress.Counter if !show { return nil } - interval := calculateProgressInterval(show) + interval := calculateProgressInterval(show, false) canUpdateStatus := stdoutCanUpdateStatus() return progress.New(interval, max, func(v uint64, max uint64, d time.Duration, final bool) {