Make path and homedir related logic more robust
Add ability to pass OONI_HOME environment variable
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user