From 90edffb1d7a14c98df16464debb79503eaa4e5c5 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Thu, 8 Mar 2018 05:07:25 -0800 Subject: [PATCH] ensure presence of home and home/db dir's during creation of the default config file --- internal/database/database.go | 13 ------------- ooni.go | 8 ++++++++ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/internal/database/database.go b/internal/database/database.go index 0421341..b9fb683 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -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 diff --git a/ooni.go b/ooni.go index 3fb6534..941f21a 100644 --- a/ooni.go +++ b/ooni.go @@ -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 }