Working on view pair crash.

This commit is contained in:
Brian Buller 2019-10-25 15:28:00 -05:00
parent 4a7ab1bc85
commit 930d064962

View File

@ -35,14 +35,28 @@ type BoltBucket struct {
errorFlag bool
}
func (b *BoltBucket) SetName(nm []byte) {
b.name = nm
func NewBoltBucket(parent *BoltBucket, name []byte) *BoltBucket {
ret := new(BoltBucket)
ret.parent = parent
ret.name = name
for _, dtk := range dataTypeNameSlice {
if _, err := datatypes[dtk].ToString(nm); err == nil {
b.nameDatatype = datatypes[dtk]
if _, err := datatypes[dtk].ToString(name); err == nil {
ret.nameDatatype = datatypes[dtk]
break
}
}
return ret
}
func (b *BoltBucket) GetPathNode() PathNode {
return PathNode{
name: b.name,
dataType: b.nameDatatype,
}
}
func (b *BoltBucket) SetName(nm []byte) {
b.name = nm
}
/*
@ -76,6 +90,13 @@ func NewBoltPair(parent *BoltBucket, key, val []byte) *BoltPair {
return &tp
}
func (p *BoltPair) GetPathNode() PathNode {
return PathNode{
name: p.key,
dataType: p.keyDatatype,
}
}
func (bd *BoltDB) getGenericFromStringPath(path []PathNode) (*BoltBucket, *BoltPair, error) {
return bd.getGenericFromPath(path)
}
@ -319,7 +340,7 @@ func (b *BoltBucket) GetStringName() string {
GetPath returns the database path leading to this BoltBucket
*/
func (b *BoltBucket) GetPath() []PathNode {
bktPath := PathNode{name: b.name, dataType: b.nameDatatype}
bktPath := b.GetPathNode()
if b.parent != nil {
return append(b.parent.GetPath(), bktPath)
}
@ -333,7 +354,7 @@ The passed prefix is the path leading to the current bucket
func (b *BoltBucket) buildVisiblePathSlice(prefix []PathNode) ([][]PathNode, error) {
var retSlice [][]PathNode
var retErr error
bucketNode := PathNode{b.name, b.nameDatatype}
bucketNode := b.GetPathNode()
retSlice = append(retSlice, append(prefix, bucketNode))
if b.expanded {
// Add subbuckets
@ -346,7 +367,7 @@ func (b *BoltBucket) buildVisiblePathSlice(prefix []PathNode) ([][]PathNode, err
}
// Add pairs
for i := range b.pairs {
retSlice = append(retSlice, append(append(prefix, bucketNode, PathNode{b.pairs[i].key, b.pairs[i].keyDatatype})))
retSlice = append(retSlice, append(append(prefix, bucketNode, b.pairs[i].GetPathNode())))
}
}
return retSlice, retErr
@ -417,7 +438,10 @@ func (p *BoltPair) GetStringVal() string {
GetPath Returns the path of the BoltPair
*/
func (p *BoltPair) GetPath() []PathNode {
return append(p.parent.GetPath(), PathNode{name: p.key, dataType: p.keyDatatype})
return append(
p.parent.GetPath(),
p.GetPathNode(),
)
}
/* This is a go-between function (between the boltbrowser structs
@ -429,7 +453,7 @@ func (p *BoltPair) GetPath() []PathNode {
*/
func addBucketFromBoltBucket(path []PathNode, bb *BoltBucket) error {
if err := insertBucket(path, bb.name); err == nil {
bucketPath := append(path, PathNode{name: bb.name, dataType: bb.nameDatatype})
bucketPath := append(path, bb.GetPathNode())
for i := range bb.pairs {
if err = insertPair(bucketPath, bb.pairs[i].key, bb.pairs[i].val); err != nil {
return err