mirror of https://github.com/etcd-io/bbolt.git
40 lines
638 B
Go
40 lines
638 B
Go
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.
|
|
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 {
|
|
println(err)
|
|
}
|
|
}
|
|
fatalln(err)
|
|
return
|
|
}
|
|
println("OK")
|
|
}
|