diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-03-28 00:07:05 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-03-29 14:22:32 -0600 |
commit | 7f2de9f17a8c6113176ecb5a3eb6ecc0772a9ec1 (patch) | |
tree | d8381077fb0d78b86219491d5331589cf470042a /cmd | |
parent | Merge pull request #97 from benbjohnson/cli (diff) | |
download | dedo-7f2de9f17a8c6113176ecb5a3eb6ecc0772a9ec1.tar.gz dedo-7f2de9f17a8c6113176ecb5a3eb6ecc0772a9ec1.tar.xz |
Add DB.Check().
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/bolt/check.go | 34 | ||||
-rw-r--r-- | cmd/bolt/main.go | 8 |
2 files changed, 42 insertions, 0 deletions
diff --git a/cmd/bolt/check.go b/cmd/bolt/check.go new file mode 100644 index 0000000..ec2ea69 --- /dev/null +++ b/cmd/bolt/check.go @@ -0,0 +1,34 @@ +package main + +import ( + "os" + + "github.com/boltdb/bolt" +) + +// Check performs a consistency check on the database and prints any errors found. +func Check(path string) { + if _, err := os.Stat(path); os.IsNotExist(err) { + fatal(err) + return + } + + db, err := bolt.Open(path, 0600) + if err != nil { + fatal(err) + return + } + defer db.Close() + + // Perform consistency check. + if err := db.Check(); err != nil { + if errors, ok := err.(bolt.ErrorList); ok { + for _, err := range errors { + println(err) + } + } + fatalln(err) + return + } + println("OK") +} diff --git a/cmd/bolt/main.go b/cmd/bolt/main.go index 6b28060..bc5fadb 100644 --- a/cmd/bolt/main.go +++ b/cmd/bolt/main.go @@ -61,6 +61,14 @@ func NewApp() *cli.App { Pages(path) }, }, + { + Name: "check", + Usage: "Performs a consistency check on the database", + Action: func(c *cli.Context) { + path := c.Args().Get(0) + Check(path) + }, + }, } return app } |