ensure presence of home and home/db dir's during creation of the default config file

This commit is contained in:
Will Scott 2018-03-08 05:07:25 -08:00
parent 7e9a4fc3b7
commit 90edffb1d7
2 changed files with 8 additions and 13 deletions

View File

@ -1,7 +1,6 @@
package database
import (
"os"
"path/filepath"
"github.com/apex/log"
@ -31,18 +30,6 @@ func RunMigrations(db *sqlx.DB) error {
// Connect to the database
func Connect(path string) (db *sqlx.DB, err error) {
home, err := ooni.GetOONIHome()
if err != nil {
return
}
if _, e := os.Stat(filepath.Join(home, "db")); e != nil {
err = os.MkdirAll(filepath.Join(home, "db"), 0700)
if err != nil {
return
}
}
db, err = sqlx.Connect("sqlite3", path)
if err != nil {
return

View File

@ -118,6 +118,14 @@ func (c *Config) Default() error {
if err != nil {
return err
}
if _, e := os.Stat(filepath.Join(home, "db")); e != nil {
err = os.MkdirAll(filepath.Join(home, "db"), 0700)
if err != nil {
return err
}
}
c.path = filepath.Join(home, "config.json")
return nil
}