mirror of
https://github.com/status-im/status-go.git
synced 2025-01-20 11:40:29 +00:00
23 lines
611 B
Go
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
|
|
}
|