diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-05-28 10:28:15 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-05-28 10:31:22 -0600 |
commit | b7896919761d1f942a042603510b30921a8c2009 (patch) | |
tree | ad956b5e92c9e371df3f10277126b6c5821ecd2e /cmd | |
parent | Merge pull request #175 from benbjohnson/check-loop (diff) | |
download | dedo-b7896919761d1f942a042603510b30921a8c2009.tar.gz dedo-b7896919761d1f942a042603510b30921a8c2009.tar.xz |
Add streaming check.
This commit changes Tx.Check() to return a channel through which check errors are returned. This allows
errors to be found before checking the entire data file.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/bolt/check.go | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/cmd/bolt/check.go b/cmd/bolt/check.go index 1436aba..1466fd7 100644 --- a/cmd/bolt/check.go +++ b/cmd/bolt/check.go @@ -21,19 +21,27 @@ func Check(path string) { defer db.Close() // Perform consistency check. - err = db.View(func(tx *bolt.Tx) error { - return tx.Check() - }) - - // Print out any errors that occur. - if err != nil { - if errors, ok := err.(bolt.ErrorList); ok { - for _, err := range errors { + _ = db.View(func(tx *bolt.Tx) error { + var count int + ch := tx.Check() + loop: + for { + select { + case err, ok := <-ch: + if !ok { + break loop + } println(err) + count++ } } - fatalln(err) - return - } - println("OK") + + // Print summary of errors. + if count > 0 { + fatalf("%d errors found") + } else { + println("OK") + } + return nil + }) } |