Skip to content

Commit

Permalink
Fix deletion of non-existing keys
Browse files Browse the repository at this point in the history
Doc for Bucket.Delete says that a Delete() on non-existing key is a
no-op. Right now it tries to delete the next key returned by the
cursor. Fix this by checking for key equivalence before deletion.

 Fixes boltdb#349

Signed-off-by: Pavel Borzenkov <pavel.borzenkov@gmail.com>
  • Loading branch information
pborzenkov authored and Anthony Romano committed Aug 11, 2017
1 parent 3c6c3ac commit 6336a42
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,12 @@ func (b *Bucket) Delete(key []byte) error {

// Move cursor to correct position.
c := b.Cursor()
_, _, flags := c.seek(key)
k, _, flags := c.seek(key)

// Return nil if the key doesn't exist.
if !bytes.Equal(key, k) {
return nil
}

// Return an error if there is already existing bucket value.
if (flags & bucketLeafFlag) != 0 {
Expand Down

0 comments on commit 6336a42

Please sign in to comment.