status-go/geth/db/db.go
2018-04-10 09:44:09 +03:00

23 lines
611 B
Go

package db
import (
"github.com/ethereum/go-ethereum/log"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt"
)
// Create returns status pointer to leveldb.DB.
func Create(path string) (*leveldb.DB, error) {
opts := &opt.Options{OpenFilesCacheCapacity: 5}
db, err := leveldb.OpenFile(path, opts)
if _, iscorrupted := err.(*errors.ErrCorrupted); iscorrupted {
log.Info("database is corrupted trying to recover", "path", path)
db, err = leveldb.RecoverFile(path, nil)
}
if err != nil {
return nil, err
}
return db, err
}