diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index e4de65752..94c0dd30d 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -29,7 +29,6 @@ import ( "github.com/restic/restic/internal/restic" "github.com/restic/restic/internal/textfile" "github.com/restic/restic/internal/ui" - "github.com/restic/restic/internal/ui/progress" "github.com/restic/restic/internal/ui/backup" ) @@ -534,8 +533,7 @@ func runBackup(ctx context.Context, opts BackupOptions, gopts global.Options, te } defer unlock() - progressReporter := backup.NewProgress(printer, - progress.CalculateProgressInterval(!gopts.Quiet, gopts.JSON, term.CanUpdateStatus())) + progressReporter := backup.NewProgress(printer, gopts.Quiet, gopts.JSON, term.CanUpdateStatus()) defer progressReporter.Done() // rejectByNameFuncs collect functions that can reject items from the backup based on path only diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index effa27c06..9648ac7f7 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -167,7 +167,7 @@ func runRestore(ctx context.Context, opts RestoreOptions, gopts global.Options, return err } - progress := restoreui.NewProgress(printer, progress.CalculateProgressInterval(!gopts.Quiet, gopts.JSON, term.CanUpdateStatus())) + progress := restoreui.NewProgress(printer, gopts.Quiet, gopts.JSON, term.CanUpdateStatus()) res := restorer.NewRestorer(repo, sn, restorer.Options{ DryRun: opts.DryRun, Sparse: opts.Sparse, diff --git a/internal/restorer/restorer_test.go b/internal/restorer/restorer_test.go index 25e4fc071..ef4533578 100644 --- a/internal/restorer/restorer_test.go +++ b/internal/restorer/restorer_test.go @@ -1103,7 +1103,7 @@ func TestRestorerOverwriteBehavior(t *testing.T) { for _, test := range tests { t.Run("", func(t *testing.T) { mock := &printerMock{Printer: progress.NewNoopPrinter()} - progress := restoreui.NewProgress(mock, 0) + progress := restoreui.NewProgress(mock, true, false, true) tempdir := saveSnapshotsAndOverwrite(t, baseSnapshot, overwriteSnapshot, Options{}, Options{Overwrite: test.Overwrite, Progress: progress}) for filename, content := range test.Files { @@ -1155,7 +1155,7 @@ func TestRestorerOverwritePartial(t *testing.T) { } mock := &printerMock{Printer: progress.NewNoopPrinter()} - progress := restoreui.NewProgress(mock, 0) + progress := restoreui.NewProgress(mock, true, false, true) saveSnapshotsAndOverwrite(t, baseSnapshot, overwriteSnapshot, Options{}, Options{Overwrite: OverwriteAlways, Progress: progress}) progress.Finish() rtest.Equals(t, restoreui.State{ diff --git a/internal/restorer/restorer_unix_test.go b/internal/restorer/restorer_unix_test.go index cad4976b4..0ee6b885a 100644 --- a/internal/restorer/restorer_unix_test.go +++ b/internal/restorer/restorer_unix_test.go @@ -89,7 +89,7 @@ func testRestorerProgressBar(t *testing.T, dryRun bool) { }, noopGetGenericAttributes) mock := &printerMock{Printer: progress.NewNoopPrinter()} - progress := restoreui.NewProgress(mock, 0) + progress := restoreui.NewProgress(mock, true, false, true) res := NewRestorer(repo, sn, Options{Progress: progress, DryRun: dryRun}) tempdir := rtest.TempDir(t) diff --git a/internal/ui/backup/progress.go b/internal/ui/backup/progress.go index 17ccfa8f4..3675a9d49 100644 --- a/internal/ui/backup/progress.go +++ b/internal/ui/backup/progress.go @@ -45,7 +45,11 @@ type Progress struct { printer ProgressPrinter } -func NewProgress(printer ProgressPrinter, interval time.Duration) *Progress { +func NewProgress(printer ProgressPrinter, quiet, json, canUpdateStatus bool) *Progress { + return newProgress(printer, progress.CalculateProgressInterval(!quiet, json, canUpdateStatus)) +} + +func newProgress(printer ProgressPrinter, interval time.Duration) *Progress { p := &Progress{ start: time.Now(), currentFiles: make(map[string]struct{}), diff --git a/internal/ui/backup/progress_test.go b/internal/ui/backup/progress_test.go index 0afd4e85d..6fa8a7ce9 100644 --- a/internal/ui/backup/progress_test.go +++ b/internal/ui/backup/progress_test.go @@ -49,7 +49,7 @@ func TestProgress(t *testing.T) { t.Parallel() prnt := &mockPrinter{Printer: progress.NewNoopPrinter()} - prog := NewProgress(prnt, time.Millisecond) + prog := newProgress(prnt, time.Millisecond) prog.StartFile("foo") prog.CompleteBlob(1024) diff --git a/internal/ui/restore/progress.go b/internal/ui/restore/progress.go index 575c7e27d..5a79d3825 100644 --- a/internal/ui/restore/progress.go +++ b/internal/ui/restore/progress.go @@ -53,7 +53,11 @@ const ( ActionDeleted ItemAction = "deleted" ) -func NewProgress(printer ProgressPrinter, interval time.Duration) *Progress { +func NewProgress(printer ProgressPrinter, quiet, json, canUpdateStatus bool) *Progress { + return newProgress(printer, progress.CalculateProgressInterval(!quiet, json, canUpdateStatus)) +} + +func newProgress(printer ProgressPrinter, interval time.Duration) *Progress { p := &Progress{ progressInfoMap: make(map[string]progressInfoEntry), started: time.Now(), diff --git a/internal/ui/restore/progress_test.go b/internal/ui/restore/progress_test.go index 85fe8f553..407d2dfba 100644 --- a/internal/ui/restore/progress_test.go +++ b/internal/ui/restore/progress_test.go @@ -58,7 +58,7 @@ func (p *mockPrinter) Finish(progress State, _ time.Duration) { func testProgress(fn func(progress *Progress) bool) (printerTrace, itemTrace, errorTrace) { printer := &mockPrinter{Printer: progress.NewNoopPrinter()} - progress := NewProgress(printer, 0) + progress := newProgress(printer, 0) final := fn(progress) progress.update(0, final) trace := append(printerTrace{}, printer.trace...)