Merge pull request #188 from ooni/informed-consent-migration

Implement informed consent migration using the config file
This commit is contained in:
Arturo Filastò 2021-01-11 11:07:31 +01:00 committed by GitHub
commit 4ac1e5f5d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 6 deletions

View File

@ -257,14 +257,24 @@ func InitDefaultConfig(home string) (*config.Config, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = ioutil.WriteFile( if err = ioutil.WriteFile(configPath, data, 0644); err != nil {
configPath,
data,
0644,
)
if err != nil {
return nil, err return nil, err
} }
// If the user did the informed consent procedure in
// probe-legacy, migrate it over.
if utils.DidLegacyInformedConsent() {
c, err := config.ReadConfig(configPath)
if err != nil {
return nil, err
}
c.Lock()
c.InformedConsent = true
c.Unlock()
if err := c.Write(); err != nil {
return nil, err
}
}
return InitDefaultConfig(home) return InitDefaultConfig(home)
} }
return nil, err return nil, err

View File

@ -41,6 +41,13 @@ func DBDir(home string, name string) string {
return filepath.Join(home, "db", fmt.Sprintf("%s.sqlite3", name)) return filepath.Join(home, "db", fmt.Sprintf("%s.sqlite3", name))
} }
// FileExists returns true if the specified path exists and is a
// regular file.
func FileExists(path string) bool {
stat, err := os.Stat(path)
return err == nil && stat.Mode().IsRegular()
}
// ResultTimestamp is a windows friendly timestamp // ResultTimestamp is a windows friendly timestamp
const ResultTimestamp = "2006-01-02T150405.999999999Z0700" const ResultTimestamp = "2006-01-02T150405.999999999Z0700"
@ -75,3 +82,17 @@ func GetOONIHome() (string, error) {
path := filepath.Join(home, ".ooniprobe") path := filepath.Join(home, ".ooniprobe")
return path, nil return path, nil
} }
// DidLegacyInformedConsent checks if the user did the informed consent procedure in probe-legacy
func DidLegacyInformedConsent() bool {
home, err := homedir.Dir()
if err != nil {
return false
}
path := filepath.Join(filepath.Join(home, ".ooni"), "initialized")
if FileExists(path) {
return true
}
return false
}