mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +00:00
Unify progress bar of check and prune commands
This commit is contained in:
parent
e915cedc3d
commit
17995dec7a
@ -5,7 +5,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
@ -99,36 +98,6 @@ func stringToIntSlice(param string) (split []uint, err error) {
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newReadProgress(gopts GlobalOptions, todo restic.Stat) *restic.Progress {
|
|
||||||
if gopts.Quiet {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
readProgress := restic.NewProgress()
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
if w := stdoutTerminalWidth(); w > 0 {
|
|
||||||
if len(status) > w {
|
|
||||||
max := w - len(status) - 4
|
|
||||||
status = status[:max] + "... "
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintProgress("%s", status)
|
|
||||||
}
|
|
||||||
|
|
||||||
readProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
|
|
||||||
fmt.Printf("\nduration: %s\n", formatDuration(d))
|
|
||||||
}
|
|
||||||
|
|
||||||
return readProgress
|
|
||||||
}
|
|
||||||
|
|
||||||
// prepareCheckCache configures a special cache directory for check.
|
// prepareCheckCache configures a special cache directory for check.
|
||||||
//
|
//
|
||||||
// * if --with-cache is specified, the default cache is used
|
// * if --with-cache is specified, the default cache is used
|
||||||
@ -281,7 +250,7 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error {
|
|||||||
Verbosef("read all data\n")
|
Verbosef("read all data\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
p := newReadProgress(gopts, restic.Stat{Blobs: packCount})
|
p := newProgressMax(!gopts.Quiet, packCount, "packs")
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
|
|
||||||
go chkr.ReadPacks(gopts.ctx, packs, p, errChan)
|
go chkr.ReadPacks(gopts.ctx, packs, p, errChan)
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/restic/restic/internal/debug"
|
"github.com/restic/restic/internal/debug"
|
||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
"github.com/restic/restic/internal/index"
|
"github.com/restic/restic/internal/index"
|
||||||
@ -47,34 +44,6 @@ func shortenStatus(maxLength int, s string) string {
|
|||||||
return s[:maxLength-3] + "..."
|
return s[:maxLength-3] + "..."
|
||||||
}
|
}
|
||||||
|
|
||||||
// newProgressMax returns a progress that counts blobs.
|
|
||||||
func newProgressMax(show bool, max uint64, description string) *restic.Progress {
|
|
||||||
if !show {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
p := restic.NewProgress()
|
|
||||||
|
|
||||||
p.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
|
||||||
status := fmt.Sprintf("[%s] %s %d / %d %s",
|
|
||||||
formatDuration(d),
|
|
||||||
formatPercent(s.Blobs, max),
|
|
||||||
s.Blobs, max, description)
|
|
||||||
|
|
||||||
if w := stdoutTerminalWidth(); w > 0 {
|
|
||||||
status = shortenStatus(w, status)
|
|
||||||
}
|
|
||||||
|
|
||||||
PrintProgress("%s", status)
|
|
||||||
}
|
|
||||||
|
|
||||||
p.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
|
|
||||||
fmt.Printf("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
func runPrune(gopts GlobalOptions) error {
|
func runPrune(gopts GlobalOptions) error {
|
||||||
repo, err := OpenRepository(gopts)
|
repo, err := OpenRepository(gopts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
36
cmd/restic/progress.go
Normal file
36
cmd/restic/progress.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/restic/restic/internal/restic"
|
||||||
|
)
|
||||||
|
|
||||||
|
// newProgressMax returns a progress that counts blobs.
|
||||||
|
func newProgressMax(show bool, max uint64, description string) *restic.Progress {
|
||||||
|
if !show {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
p := restic.NewProgress()
|
||||||
|
|
||||||
|
p.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
|
status := fmt.Sprintf("[%s] %s %d / %d %s",
|
||||||
|
formatDuration(d),
|
||||||
|
formatPercent(s.Blobs, max),
|
||||||
|
s.Blobs, max, description)
|
||||||
|
|
||||||
|
if w := stdoutTerminalWidth(); w > 0 {
|
||||||
|
status = shortenStatus(w, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintProgress("%s", status)
|
||||||
|
}
|
||||||
|
|
||||||
|
p.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
|
||||||
|
fmt.Printf("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user