mirror of
https://github.com/lingble/databunker.git
synced 2026-03-20 03:53:43 +00:00
Add -db argument
This commit is contained in:
@@ -211,6 +211,7 @@ func main() {
|
||||
//fmt.Printf("%+v\n", cfg)
|
||||
initPtr := flag.Bool("init", false, "a bool")
|
||||
masterKeyPtr := flag.String("masterkey", "", "master key")
|
||||
dbPtr := flag.String("db", "", "database file")
|
||||
flag.Parse()
|
||||
var err error
|
||||
var masterKey []byte
|
||||
@@ -234,9 +235,9 @@ func main() {
|
||||
db.closeDB()
|
||||
os.Exit(0)
|
||||
}
|
||||
if dbExists() == false {
|
||||
if dbExists(dbPtr) == false {
|
||||
fmt.Println("\ndatabunker.db file is missing.\n")
|
||||
fmt.Println(`Run "./databunker -init" for the first time.`)
|
||||
fmt.Println(`Run "./databunker -init" for the first time to init database.`)
|
||||
fmt.Println("")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
18
src/qldb.go
18
src/qldb.go
@@ -33,17 +33,27 @@ type dbcon struct {
|
||||
hash []byte
|
||||
}
|
||||
|
||||
func dbExists() bool {
|
||||
if _, err := os.Stat("databunker.db"); os.IsNotExist(err) {
|
||||
func dbExists(filepath *string) bool {
|
||||
dbfile := "./databunker.db"
|
||||
if filepath != nil {
|
||||
if len(*filepath) > 0 {
|
||||
dbfile = *filepath
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(dbfile); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func newDB(masterKey []byte, urlurl *string) (dbcon, error) {
|
||||
func newDB(masterKey []byte, filepath *string) (dbcon, error) {
|
||||
dbobj := dbcon{nil, nil, nil}
|
||||
dbfile := "./databunker.db"
|
||||
|
||||
if filepath != nil {
|
||||
if len(*filepath) > 0 {
|
||||
dbfile = *filepath
|
||||
}
|
||||
}
|
||||
// collect list of all tables
|
||||
if _, err := os.Stat(dbfile); !os.IsNotExist(err) {
|
||||
db2, err := ql.OpenFile(dbfile, &ql.Options{FileFormat: 2})
|
||||
|
||||
Reference in New Issue
Block a user