check: Better differentiate between warnings and errors

This commit is contained in:
Michael Eischer 2022-05-09 22:25:36 +02:00
parent 5815f727ee
commit 59eb132dcd

View file

@ -219,15 +219,20 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error {
Verbosef("load indexes\n") Verbosef("load indexes\n")
hints, errs := chkr.LoadIndex(gopts.ctx) hints, errs := chkr.LoadIndex(gopts.ctx)
dupFound := false errorsFound := false
suggestIndexRebuild := false
for _, hint := range hints { for _, hint := range hints {
switch hint.(type) {
case *checker.ErrDuplicatePacks, *checker.ErrOldIndexFormat:
Printf("%v\n", hint) Printf("%v\n", hint)
if _, ok := hint.(*checker.ErrDuplicatePacks); ok { suggestIndexRebuild = true
dupFound = true default:
Warnf("error: %v\n", hint)
errorsFound = true
} }
} }
if dupFound { if suggestIndexRebuild {
Printf("This is non-critical, you can run `restic rebuild-index' to correct this\n") Printf("This is non-critical, you can run `restic rebuild-index' to correct this\n")
} }
@ -238,7 +243,6 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error {
return errors.Fatal("LoadIndex returned errors") return errors.Fatal("LoadIndex returned errors")
} }
errorsFound := false
orphanedPacks := 0 orphanedPacks := 0
errChan := make(chan error) errChan := make(chan error)
@ -252,11 +256,11 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error {
continue continue
} }
errorsFound = true errorsFound = true
Warnf("%v\n", err) Warnf("error: %v\n", err)
} }
if orphanedPacks > 0 { if orphanedPacks > 0 {
Verbosef("%d additional files were found in the repo, which likely contain duplicate data.\nYou can run `restic prune` to correct this.\n", orphanedPacks) Verbosef("%d additional files were found in the repo, which likely contain duplicate data.\nThis is non-critical, you can run `restic prune` to correct this.\n", orphanedPacks)
} }
Verbosef("check snapshots, trees and blobs\n") Verbosef("check snapshots, trees and blobs\n")