Commit 966467cf authored by Jakub Sztandera's avatar Jakub Sztandera Committed by GitHub

Merge pull request #3 from ipfs-filestore/leveldb-fix

Fix bug in LevelDB datastore's Delete() method.
parents 3a579732 3c980c5a
...@@ -58,11 +58,17 @@ func (d *datastore) Has(key ds.Key) (exists bool, err error) { ...@@ -58,11 +58,17 @@ func (d *datastore) Has(key ds.Key) (exists bool, err error) {
} }
func (d *datastore) Delete(key ds.Key) (err error) { func (d *datastore) Delete(key ds.Key) (err error) {
err = d.DB.Delete(key.Bytes(), nil) // leveldb Delete will not return an error if the key doesn't
if err == leveldb.ErrNotFound { // exist (see https://github.com/syndtr/goleveldb/issues/109),
// so check that the key exists first and if not return an
// error
exists, err := d.DB.Has(key.Bytes(), nil)
if !exists {
return ds.ErrNotFound return ds.ErrNotFound
} } else if err != nil {
return err return err
}
return d.DB.Delete(key.Bytes(), nil)
} }
func (d *datastore) Query(q dsq.Query) (dsq.Results, error) { func (d *datastore) Query(q dsq.Query) (dsq.Results, error) {
......
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