mirror of
https://github.com/restic/restic.git
synced 2026-06-24 01:24:19 +00:00
backup,restore: move CalculateProgressInterval call to their ui package
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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{}),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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...)
|
||||
|
||||
Reference in New Issue
Block a user