check: add progress bar to the tree structure check
This commit is contained in:
parent
505f8a2229
commit
e2b0072441
5 changed files with 13 additions and 6 deletions
|
@ -240,7 +240,11 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error {
|
||||||
|
|
||||||
Verbosef("check snapshots, trees and blobs\n")
|
Verbosef("check snapshots, trees and blobs\n")
|
||||||
errChan = make(chan error)
|
errChan = make(chan error)
|
||||||
go chkr.Structure(gopts.ctx, errChan)
|
go func() {
|
||||||
|
bar := newProgressMax(!gopts.Quiet, 0, "snapshots")
|
||||||
|
defer bar.Done()
|
||||||
|
chkr.Structure(gopts.ctx, bar, errChan)
|
||||||
|
}()
|
||||||
|
|
||||||
for err := range errChan {
|
for err := range errChan {
|
||||||
errorsFound = true
|
errorsFound = true
|
||||||
|
|
|
@ -354,8 +354,9 @@ func loadSnapshotTreeIDs(ctx context.Context, repo restic.Repository) (ids resti
|
||||||
// Structure checks that for all snapshots all referenced data blobs and
|
// Structure checks that for all snapshots all referenced data blobs and
|
||||||
// subtrees are available in the index. errChan is closed after all trees have
|
// subtrees are available in the index. errChan is closed after all trees have
|
||||||
// been traversed.
|
// been traversed.
|
||||||
func (c *Checker) Structure(ctx context.Context, errChan chan<- error) {
|
func (c *Checker) Structure(ctx context.Context, p *progress.Counter, errChan chan<- error) {
|
||||||
trees, errs := loadSnapshotTreeIDs(ctx, c.repo)
|
trees, errs := loadSnapshotTreeIDs(ctx, c.repo)
|
||||||
|
p.SetMax(uint64(len(trees)))
|
||||||
debug.Log("need to check %d trees from snapshots, %d errs returned", len(trees), len(errs))
|
debug.Log("need to check %d trees from snapshots, %d errs returned", len(trees), len(errs))
|
||||||
|
|
||||||
for _, err := range errs {
|
for _, err := range errs {
|
||||||
|
@ -376,7 +377,7 @@ func (c *Checker) Structure(ctx context.Context, errChan chan<- error) {
|
||||||
c.blobRefs.M.Insert(h)
|
c.blobRefs.M.Insert(h)
|
||||||
c.blobRefs.Unlock()
|
c.blobRefs.Unlock()
|
||||||
return blobReferenced
|
return blobReferenced
|
||||||
}, nil)
|
}, p)
|
||||||
|
|
||||||
defer close(errChan)
|
defer close(errChan)
|
||||||
for i := 0; i < defaultParallelism; i++ {
|
for i := 0; i < defaultParallelism; i++ {
|
||||||
|
|
|
@ -43,7 +43,9 @@ func checkPacks(chkr *checker.Checker) []error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkStruct(chkr *checker.Checker) []error {
|
func checkStruct(chkr *checker.Checker) []error {
|
||||||
return collectErrors(context.TODO(), chkr.Structure)
|
return collectErrors(context.TODO(), func(ctx context.Context, errChan chan<- error) {
|
||||||
|
chkr.Structure(ctx, nil, errChan)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkData(chkr *checker.Checker) []error {
|
func checkData(chkr *checker.Checker) []error {
|
||||||
|
|
|
@ -30,7 +30,7 @@ func TestCheckRepo(t testing.TB, repo restic.Repository) {
|
||||||
|
|
||||||
// structure
|
// structure
|
||||||
errChan = make(chan error)
|
errChan = make(chan error)
|
||||||
go chkr.Structure(context.TODO(), errChan)
|
go chkr.Structure(context.TODO(), nil, errChan)
|
||||||
|
|
||||||
for err := range errChan {
|
for err := range errChan {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
|
|
@ -368,7 +368,7 @@ func TestIndexSave(t *testing.T) {
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
errCh := make(chan error)
|
errCh := make(chan error)
|
||||||
go checker.Structure(ctx, errCh)
|
go checker.Structure(ctx, nil, errCh)
|
||||||
i := 0
|
i := 0
|
||||||
for err := range errCh {
|
for err := range errCh {
|
||||||
t.Errorf("checker returned error: %v", err)
|
t.Errorf("checker returned error: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue