From efb7e87d1b66a7a5dad48f460a8f8cb553a3761c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Mon, 19 Mar 2018 11:23:54 +0100 Subject: [PATCH] Refactor the EnsureDefaultConfigDir() function --- ooni.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/ooni.go b/ooni.go index 25ce528..c2d352b 100644 --- a/ooni.go +++ b/ooni.go @@ -147,19 +147,20 @@ func ParseConfig(b []byte) (*Config, error) { return c, nil } -func EnsureDefaultConfigDir() error { +//EnsureDefaultOONIHomeDir makes sure the paths to the OONI Home exist +func EnsureDefaultOONIHomeDir() (string, error) { home, err := GetOONIHome() if err != nil { - return err + 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 + return "", err } } - return nil + return home, nil } // ReadConfig reads the configuration from the path @@ -167,9 +168,6 @@ func ReadConfig(path string) (*Config, error) { b, err := ioutil.ReadFile(path) if os.IsNotExist(err) { - if err = EnsureDefaultConfigDir(); err != nil { - return nil, errors.Wrap(err, "Creating new config") - } c := &Config{} if err = c.Default(); err != nil { @@ -197,7 +195,7 @@ func ReadConfig(path string) (*Config, error) { // ReadDefaultConfigPaths from common locations. func ReadDefaultConfigPaths() (*Config, error) { - home, err := GetOONIHome() + home, err := EnsureDefaultOONIHomeDir() if err != nil { return nil, errors.Wrap(err, "reading default config paths") }