Skip to content

Commit

Permalink
recover datastore on corruption
Browse files Browse the repository at this point in the history
(but not if we're opening it read-only)

fixes ipfs/kubo#4981
  • Loading branch information
Stebalien committed May 5, 2018
1 parent 91a917a commit 6019782
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
dsq "github.com/ipfs/go-datastore/query"
"github.com/jbenet/goprocess"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/errors"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/storage"
"github.com/syndtr/goleveldb/leveldb/util"
Expand Down Expand Up @@ -38,6 +39,9 @@ func NewDatastore(path string, opts *Options) (*datastore, error) {
db, err = leveldb.Open(storage.NewMemStorage(), &nopts)
} else {
db, err = leveldb.OpenFile(path, &nopts)
if errors.IsCorrupted(err) && !nopts.GetReadOnly() {
db, err = leveldb.RecoverFile(path, &nopts)
}
}

if err != nil {
Expand Down

0 comments on commit 6019782

Please sign in to comment.