Fix nil pointer panic when meta bucket is missing
If NewQuadStore was called without first calling InitQuadStore, the runtime would panic since the meta bucket never was created.
This commit is contained in:
parent
7c0d8b28b0
commit
6f6e14ee52
1 changed files with 10 additions and 1 deletions
|
|
@ -37,6 +37,10 @@ func init() {
|
|||
}
|
||||
|
||||
var (
|
||||
errNoBucket = errors.New("bolt: bucket is missing")
|
||||
)
|
||||
|
||||
var (
|
||||
hashPool = sync.Pool{
|
||||
New: func() interface{} { return sha1.New() },
|
||||
}
|
||||
|
|
@ -97,7 +101,9 @@ func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) {
|
|||
return nil, err
|
||||
}
|
||||
err = qs.getMetadata()
|
||||
if err != nil {
|
||||
if err == errNoBucket {
|
||||
panic("bolt: quadstore has not been initialised")
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &qs, nil
|
||||
|
|
@ -451,6 +457,9 @@ func (qs *QuadStore) SizeOf(k graph.Value) int64 {
|
|||
func (qs *QuadStore) getInt64ForKey(tx *bolt.Tx, key string, empty int64) (int64, error) {
|
||||
var out int64
|
||||
b := tx.Bucket(metaBucket)
|
||||
if b == nil {
|
||||
return empty, errNoBucket
|
||||
}
|
||||
data := b.Get([]byte(key))
|
||||
if data == nil {
|
||||
return empty, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue