diff options
author | Alexander Neumann <alexander@bumpern.de> | 2015-12-06 17:29:31 +0100 |
---|---|---|
committer | Alexander Neumann <alexander@bumpern.de> | 2015-12-06 17:29:31 +0100 |
commit | 3ac1d0e4d11c9e0d20e6fa653ae9065529b338e9 (patch) | |
tree | db53a015b7bd4cf070a05e79b189bb532dbbe70d /cmd | |
parent | 0e66a66bce4e4cca02a6a5bdb420bf3bb24b3540 (diff) |
add progress
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/restic/cmd_check.go | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index 4712ba004..8c59c2ffe 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -4,7 +4,11 @@ import ( "errors" "fmt" "os" + "time" + "golang.org/x/crypto/ssh/terminal" + + "github.com/restic/restic" "github.com/restic/restic/checker" ) @@ -29,6 +33,37 @@ func (cmd CmdCheck) Usage() string { return "[check-options]" } +func (cmd CmdCheck) newReadProgress(todo restic.Stat) *restic.Progress { + if !cmd.global.ShowProgress() { + return nil + } + + readProgress := restic.NewProgress(time.Second) + + readProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) { + status := fmt.Sprintf("[%s] %s %d / %d items", + formatDuration(d), + formatPercent(s.Blobs, todo.Blobs), + s.Blobs, todo.Blobs) + + w, _, err := terminal.GetSize(int(os.Stdout.Fd())) + if err == nil { + if len(status) > w { + max := w - len(status) - 4 + status = status[:max] + "... " + } + } + + fmt.Printf("\x1b[2K%s\r", status) + } + + readProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) { + fmt.Printf("\nduration: %s\n", formatDuration(d)) + } + + return readProgress +} + func (cmd CmdCheck) Execute(args []string) error { if len(args) != 0 { return errors.New("check has no arguments") @@ -110,11 +145,12 @@ func (cmd CmdCheck) Execute(args []string) error { } if cmd.ReadData { - cmd.global.Verbosef("reading all data\n") + cmd.global.Verbosef("Read all data\n") + p := cmd.newReadProgress(restic.Stat{Blobs: chkr.CountPacks()}) errChan := make(chan error) - go chkr.ReadData(errChan, done) + go chkr.ReadData(p, errChan, done) for err := range errChan { errorsFound = true |