Unverified Commit 6975172d authored by ucwong's avatar ucwong Committed by GitHub

whisper/mailserver : recover corrupt db files before opening (#20891)

* whisper/mailserver : recover db file when openfile corrupted

* whisper/mailserver : fix db -> s.db

* whisper/mailserver : common/errors for dbfile
parent c8e9a916
...@@ -27,6 +27,7 @@ import ( ...@@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
whisper "github.com/ethereum/go-ethereum/whisper/whisperv6" whisper "github.com/ethereum/go-ethereum/whisper/whisperv6"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt" "github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/util" "github.com/syndtr/goleveldb/leveldb/util"
) )
...@@ -70,6 +71,9 @@ func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, p ...@@ -70,6 +71,9 @@ func (s *WMailServer) Init(shh *whisper.Whisper, path string, password string, p
} }
s.db, err = leveldb.OpenFile(path, &opt.Options{OpenFilesCacheCapacity: 32}) s.db, err = leveldb.OpenFile(path, &opt.Options{OpenFilesCacheCapacity: 32})
if _, iscorrupted := err.(*errors.ErrCorrupted); iscorrupted {
s.db, err = leveldb.RecoverFile(path, nil)
}
if err != nil { if err != nil {
return fmt.Errorf("open DB file: %s", err) return fmt.Errorf("open DB file: %s", err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment