Add -db argument

This commit is contained in:
stremovsky
2019-12-15 09:53:02 +02:00
parent b19486fed5
commit b77799ed4e
2 changed files with 17 additions and 6 deletions

View File

@@ -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)
}

View File

@@ -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})