Use Has instead of Get for existence test.

This commit is contained in:
beorn7 2015-07-16 12:25:32 +02:00
parent ff08f0b6fe
commit 502aa9ded5
1 changed files with 2 additions and 6 deletions

View File

@ -110,12 +110,8 @@ func (l *LevelDB) Delete(key encoding.BinaryMarshaler) (bool, error) {
return false, err
}
// Note that Delete returns nil if k does not exist. So we have to test
// for existence with Get first.
_, err = l.storage.Get(k, l.readOpts)
if err == leveldb.ErrNotFound {
return false, nil
}
if err != nil {
// for existence with Has first.
if has, err := l.storage.Has(k, l.readOpts); !has || err != nil {
return false, err
}
if err = l.storage.Delete(k, l.writeOpts); err != nil {