Move all directory related functionality into paths utils
As per suggestion by @willscott in: https://github.com/OpenObservatory/gooni/pull/9#discussion_r176760264
This commit is contained in:
parent
79c940022b
commit
cffb9ea74c
4 changed files with 54 additions and 31 deletions
13
ooni.go
13
ooni.go
|
|
@ -59,9 +59,9 @@ func (c *Context) MaybeLocationLookup() error {
|
|||
func (c *Context) LocationLookup() error {
|
||||
var err error
|
||||
|
||||
dbPath := filepath.Join(c.Home, "geoip")
|
||||
geoipDir := utils.GeoIPDir(c.Home)
|
||||
|
||||
c.Location, err = utils.GeoIPLookup(dbPath)
|
||||
c.Location, err = utils.GeoIPLookup(geoipDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ func (c *Context) Init() error {
|
|||
return err
|
||||
}
|
||||
|
||||
c.dbPath = filepath.Join(c.Home, "db", "main.sqlite3")
|
||||
c.dbPath = utils.DBDir(c.Home, "main")
|
||||
if c.Config.InformedConsent == false {
|
||||
if err = Onboarding(c.Config); err != nil {
|
||||
return errors.Wrap(err, "onboarding")
|
||||
|
|
@ -215,11 +215,10 @@ func ParseConfig(b []byte) (*Config, error) {
|
|||
// MaybeInitializeHome does the setup for a new OONI Home
|
||||
func MaybeInitializeHome(home string) error {
|
||||
firstRun := false
|
||||
requiredDirs := []string{"db", "msmts", "geoip"}
|
||||
for _, d := range requiredDirs {
|
||||
if _, e := os.Stat(filepath.Join(home, d)); e != nil {
|
||||
for _, d := range utils.RequiredDirs(home) {
|
||||
if _, e := os.Stat(d); e != nil {
|
||||
firstRun = true
|
||||
if err := os.MkdirAll(filepath.Join(home, d), 0700); err != nil {
|
||||
if err := os.MkdirAll(d, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue