Implement informed consent migration using the config file
This commit is contained in:
parent
8df91ecb1b
commit
5cfce6acd0
|
@ -257,14 +257,24 @@ func InitDefaultConfig(home string) (*config.Config, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = ioutil.WriteFile(
|
||||
configPath,
|
||||
data,
|
||||
0644,
|
||||
)
|
||||
if err = ioutil.WriteFile(configPath, data, 0644); err != nil {
|
||||
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 nil, err
|
||||
|
|
|
@ -41,6 +41,13 @@ func DBDir(home string, name string) string {
|
|||
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
|
||||
const ResultTimestamp = "2006-01-02T150405.999999999Z0700"
|
||||
|
||||
|
@ -75,3 +82,17 @@ func GetOONIHome() (string, error) {
|
|||
path := filepath.Join(home, ".ooniprobe")
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user