Merge branch 'master' of github.com:br0xen/boltbrowser
This commit is contained in:
commit
fcc13603da
@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
/*
|
||||
@ -268,8 +268,8 @@ func (bd *BoltDB) syncOpenBuckets(shadow *BoltDB) {
|
||||
func (bd *BoltDB) refreshDatabase() *BoltDB {
|
||||
// Reload the database into memBolt
|
||||
memBolt = new(BoltDB)
|
||||
db.View(func(tx *bolt.Tx) error {
|
||||
err := tx.ForEach(func(nm []byte, b *bolt.Bucket) error {
|
||||
db.View(func(tx *bbolt.Tx) error {
|
||||
err := tx.ForEach(func(nm []byte, b *bbolt.Bucket) error {
|
||||
bb, err := readBucket(b)
|
||||
if err == nil {
|
||||
bb.name = string(nm)
|
||||
@ -406,7 +406,7 @@ func deleteKey(path []string) error {
|
||||
if AppArgs.ReadOnly {
|
||||
return errors.New("DB is in Read-Only Mode")
|
||||
}
|
||||
err := db.Update(func(tx *bolt.Tx) error {
|
||||
err := db.Update(func(tx *bbolt.Tx) error {
|
||||
// len(b.path)-1 is the key we need to delete,
|
||||
// the rest are buckets leading to that key
|
||||
if len(path) == 1 {
|
||||
@ -442,7 +442,7 @@ func deleteKey(path []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func readBucket(b *bolt.Bucket) (*BoltBucket, error) {
|
||||
func readBucket(b *bbolt.Bucket) (*BoltBucket, error) {
|
||||
bb := new(BoltBucket)
|
||||
if b == nil {
|
||||
return nil, errors.New("No bucket passed")
|
||||
@ -471,7 +471,7 @@ func renameBucket(path []string, name string) error {
|
||||
return nil
|
||||
}
|
||||
var bb *BoltBucket // For caching the current bucket
|
||||
err := db.View(func(tx *bolt.Tx) error {
|
||||
err := db.View(func(tx *bbolt.Tx) error {
|
||||
// len(b.path)-1 is the key we need to delete,
|
||||
// the rest are buckets leading to that key
|
||||
b := tx.Bucket([]byte(path[0]))
|
||||
@ -525,7 +525,7 @@ func updatePairKey(path []string, k string) error {
|
||||
if AppArgs.ReadOnly {
|
||||
return errors.New("DB is in Read-Only Mode")
|
||||
}
|
||||
err := db.Update(func(tx *bolt.Tx) error {
|
||||
err := db.Update(func(tx *bbolt.Tx) error {
|
||||
// len(b.path)-1 is the key for the pair we're updating,
|
||||
// the rest are buckets leading to that key
|
||||
b := tx.Bucket([]byte(path[0]))
|
||||
@ -561,7 +561,7 @@ func updatePairValue(path []string, v string) error {
|
||||
if AppArgs.ReadOnly {
|
||||
return errors.New("DB is in Read-Only Mode")
|
||||
}
|
||||
err := db.Update(func(tx *bolt.Tx) error {
|
||||
err := db.Update(func(tx *bbolt.Tx) error {
|
||||
// len(b.GetPath())-1 is the key for the pair we're updating,
|
||||
// the rest are buckets leading to that key
|
||||
b := tx.Bucket([]byte(path[0]))
|
||||
@ -592,7 +592,7 @@ func insertBucket(path []string, n string) error {
|
||||
return errors.New("DB is in Read-Only Mode")
|
||||
}
|
||||
// Inserts a new bucket named 'n' at 'path'
|
||||
err := db.Update(func(tx *bolt.Tx) error {
|
||||
err := db.Update(func(tx *bbolt.Tx) error {
|
||||
if len(path) == 0 || path[0] == "" {
|
||||
// insert at root
|
||||
_, err := tx.CreateBucket([]byte(n))
|
||||
@ -632,7 +632,7 @@ func insertPair(path []string, k string, v string) error {
|
||||
return errors.New("DB is in Read-Only Mode")
|
||||
}
|
||||
// Insert a new pair k => v at path
|
||||
err := db.Update(func(tx *bolt.Tx) error {
|
||||
err := db.Update(func(tx *bbolt.Tx) error {
|
||||
if len(path) == 0 {
|
||||
// We cannot insert a pair at root
|
||||
return errors.New("insertPair: Cannot insert pair at root")
|
||||
@ -663,7 +663,7 @@ func insertPair(path []string, k string, v string) error {
|
||||
}
|
||||
|
||||
func exportValue(path []string, fName string) error {
|
||||
return db.View(func(tx *bolt.Tx) error {
|
||||
return db.View(func(tx *bbolt.Tx) error {
|
||||
// len(b.path)-1 is the key whose value we want to export
|
||||
// the rest are buckets leading to that key
|
||||
b := tx.Bucket([]byte(path[0]))
|
||||
@ -689,7 +689,7 @@ func exportValue(path []string, fName string) error {
|
||||
}
|
||||
|
||||
func exportJSON(path []string, fName string) error {
|
||||
return db.View(func(tx *bolt.Tx) error {
|
||||
return db.View(func(tx *bbolt.Tx) error {
|
||||
// len(b.path)-1 is the key whose value we want to export
|
||||
// the rest are buckets leading to that key
|
||||
b := tx.Bucket([]byte(path[0]))
|
||||
@ -719,7 +719,7 @@ func exportJSON(path []string, fName string) error {
|
||||
})
|
||||
}
|
||||
|
||||
func genJSONString(b *bolt.Bucket) string {
|
||||
func genJSONString(b *bbolt.Bucket) string {
|
||||
ret := "{"
|
||||
b.ForEach(func(k, v []byte) error {
|
||||
ret = fmt.Sprintf("%s\"%s\":", ret, string(k))
|
||||
@ -761,7 +761,7 @@ func importValue(path []string, fName string) error {
|
||||
if AppArgs.ReadOnly {
|
||||
return errors.New("DB is in Read-Only Mode")
|
||||
}
|
||||
return db.Update(func(tx *bolt.Tx) error {
|
||||
return db.Update(func(tx *bbolt.Tx) error {
|
||||
// len(b.GetPath())-1 is the key for the pair we're updating,
|
||||
// the rest are buckets leading to that key
|
||||
b := tx.Bucket([]byte(path[0]))
|
||||
|
4
go.mod
4
go.mod
@ -1,14 +1,14 @@
|
||||
module github.com/br0xen/boltbrowser
|
||||
|
||||
require (
|
||||
github.com/boltdb/bolt v1.3.1
|
||||
github.com/br0xen/termbox-util v0.0.0-20170904143325-de1d4c83380e
|
||||
github.com/nsf/termbox-go v1.1.1
|
||||
go.etcd.io/bbolt v1.3.7
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/mattn/go-runewidth v0.0.9 // indirect
|
||||
golang.org/x/sys v0.6.0 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
)
|
||||
|
||||
go 1.20
|
||||
|
12
go.sum
12
go.sum
@ -1,10 +1,14 @@
|
||||
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/br0xen/termbox-util v0.0.0-20170904143325-de1d4c83380e h1:PF4gYXcZfTbAoAk5DPZcvjmq8gyg4gpcmWdT8W+0X1c=
|
||||
github.com/br0xen/termbox-util v0.0.0-20170904143325-de1d4c83380e/go.mod h1:x9wJlgOj74OFTOBwXOuO8pBguW37EgYNx51Dbjkfzo4=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY=
|
||||
github.com/nsf/termbox-go v1.1.1/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo=
|
||||
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ=
|
||||
go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
|
||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
|
8
main.go
8
main.go
@ -7,15 +7,15 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/nsf/termbox-go"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
var ProgramName = "boltbrowser"
|
||||
var VersionNum = 2.0
|
||||
|
||||
var databaseFiles []string
|
||||
var db *bolt.DB
|
||||
var db *bbolt.DB
|
||||
var memBolt *BoltDB
|
||||
|
||||
var currentFilename string
|
||||
@ -114,8 +114,8 @@ func main() {
|
||||
|
||||
for _, databaseFile := range databaseFiles {
|
||||
currentFilename = databaseFile
|
||||
db, err = bolt.Open(databaseFile, 0600, &bolt.Options{Timeout: AppArgs.DBOpenTimeout})
|
||||
if err == bolt.ErrTimeout {
|
||||
db, err = bbolt.Open(databaseFile, 0600, &bbolt.Options{Timeout: AppArgs.DBOpenTimeout})
|
||||
if err == bbolt.ErrTimeout {
|
||||
termbox.Close()
|
||||
fmt.Printf("File %s is locked. Make sure it's not used by another app and try again\n", databaseFile)
|
||||
os.Exit(1)
|
||||
|
@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package main
|
||||
|
Loading…
Reference in New Issue
Block a user