V3 is off to a great start!

This commit is contained in:
2022-04-27 17:13:05 -05:00
parent 7443259b23
commit c2d2c04b1a
10 changed files with 838 additions and 142 deletions

View File

@@ -26,6 +26,7 @@ func NewBoltDB(db *bolt.DB) *BoltDB {
func (bd *BoltDB) RefreshDatabase() {
// Reload the database from the file
shadowBuckets := bd.buckets
bd.buckets = []BoltBucket{}
bd.db.View(func(tx *bolt.Tx) error {
err := tx.ForEach(func(nm []byte, b *bolt.Bucket) error {
@@ -51,6 +52,7 @@ func (bd *BoltDB) RefreshDatabase() {
}
return err
})
bd.SyncOpenBuckets(shadowBuckets)
}
func (bd *BoltDB) GetBuckets() []BoltBucket { return bd.buckets }
@@ -271,12 +273,12 @@ func (bd *BoltDB) OpenAllBuckets() {
}
}
func (bd *BoltDB) SyncOpenBuckets(shadow *BoltDB) {
func (bd *BoltDB) SyncOpenBuckets(shadow []BoltBucket) {
// First test this bucket
for i := range bd.buckets {
for j := range shadow.buckets {
if bd.buckets[i].name == shadow.buckets[j].name {
bd.buckets[i].SyncOpenBuckets(&shadow.buckets[j])
for j := range shadow {
if bd.buckets[i].name == shadow[j].name {
bd.buckets[i].SyncOpenBuckets(&shadow[j])
}
}
}
@@ -527,7 +529,7 @@ func (bd *BoltDB) InsertPair(path []string, k string, v string) error {
return err
}
func (bd *BoltDB) exportValue(path []string, fName string) error {
func (bd *BoltDB) ExportValue(path []string, fName string) error {
return bd.db.View(func(tx *bolt.Tx) error {
// len(b.path)-1 is the key whose value we want to export
// the rest are buckets leading to that key

View File

@@ -19,6 +19,11 @@ type BoltBucket struct {
isRoot bool
}
func (b *BoltBucket) GetName() string { return b.name }
func (b *BoltBucket) SetName(nm string) { b.name = nm }
func (b *BoltBucket) GetBuckets() []BoltBucket { return b.buckets }
func (b *BoltBucket) GetPairs() []BoltPair { return b.pairs }
/*
GetPath returns the database path leading to this BoltBucket
*/

View File

@@ -14,10 +14,7 @@ type BoltPair struct {
/*
GetPath Returns the path of the BoltPair
*/
func (p *BoltPair) GetPath() []string {
return append(p.parent.GetPath(), p.key)
}
func (p BoltPair) String() string {
return fmt.Sprintf("%s: %s", p.key, p.val)
}
func (p *BoltPair) GetPath() []string { return append(p.parent.GetPath(), p.key) }
func (p *BoltPair) GetKey() string { return p.key }
func (p *BoltPair) GetValue() string { return p.val }
func (p BoltPair) String() string { return fmt.Sprintf("%s: %s", p.key, p.val) }