Browse Source

libnetwork/internal/kvstore/boltdb: BoltDB.Exists(): fix error handling

This function could potentially return "true" even if an error was returned.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 2 years ago
parent
commit
fb61b07bcf
1 changed files with 7 additions and 2 deletions
  1. 7 2
      libnetwork/internal/kvstore/boltdb/boltdb.go

+ 7 - 2
libnetwork/internal/kvstore/boltdb/boltdb.go

@@ -220,8 +220,13 @@ func (b *BoltDB) Exists(key string) (bool, error) {
 		exists = len(bucket.Get([]byte(key))) > 0
 		exists = len(bucket.Get([]byte(key))) > 0
 		return nil
 		return nil
 	})
 	})
-
-	return exists, err
+	if err != nil {
+		return false, err
+	}
+	if !exists {
+		return false, store.ErrKeyNotFound
+	}
+	return true, nil
 }
 }
 
 
 // List returns the range of keys starting with the passed in prefix
 // List returns the range of keys starting with the passed in prefix