aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-05-28 10:28:15 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-05-28 10:31:22 -0600
commitb7896919761d1f942a042603510b30921a8c2009 (patch)
treead956b5e92c9e371df3f10277126b6c5821ecd2e /cmd
parentMerge pull request #175 from benbjohnson/check-loop (diff)
downloaddedo-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.go32
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
+ })
}