Make path and homedir related logic more robust

Add ability to pass OONI_HOME environment variable
This commit is contained in:
Arturo Filastò
2018-05-21 17:33:59 -07:00
parent e0ac7b337b
commit c620bc9726
5 changed files with 32 additions and 23 deletions
+17
View File
@@ -6,6 +6,8 @@ import (
"os"
"path/filepath"
"time"
"github.com/ooni/probe-cli/utils/homedir"
)
// RequiredDirs returns the required ooni home directories
@@ -46,3 +48,18 @@ func MakeResultsDir(home string, name string, ts time.Time) (string, error) {
}
return p, nil
}
// GetOONIHome returns the path to the OONI Home
func GetOONIHome() (string, error) {
if ooniHome := os.Getenv("OONI_HOME"); ooniHome != "" {
return ooniHome, nil
}
home, err := homedir.Dir()
if err != nil {
return "", err
}
path := filepath.Join(home, ".ooni")
return path, nil
}