refactor(ooniprobe): migrate database to internal (#979)
See https://github.com/ooni/probe/issues/2352 Co-authored-by: decfox <decfox@github.com> Co-authored-by: Simone Basso <bassosimone@gmail.com>
This commit is contained in:
parent
d6def35286
commit
6b01264373
20 changed files with 53 additions and 56 deletions
|
|
@ -1,11 +1,9 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/utils/homedir"
|
||||
)
|
||||
|
|
@ -53,26 +51,6 @@ func FileExists(path string) bool {
|
|||
return err == nil && stat.Mode().IsRegular()
|
||||
}
|
||||
|
||||
// ResultTimestamp is a windows friendly timestamp
|
||||
const ResultTimestamp = "2006-01-02T150405.999999999Z0700"
|
||||
|
||||
// MakeResultsDir creates and returns a directory for the result
|
||||
func MakeResultsDir(home string, name string, ts time.Time) (string, error) {
|
||||
p := filepath.Join(home, "msmts",
|
||||
fmt.Sprintf("%s-%s", name, ts.Format(ResultTimestamp)))
|
||||
|
||||
// If the path already exists, this is a problem. It should not clash, because
|
||||
// we are using nanosecond precision for the starttime.
|
||||
if _, e := os.Stat(p); e == nil {
|
||||
return "", errors.New("results path already exists")
|
||||
}
|
||||
err := os.MkdirAll(p, 0700)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// GetOONIHome returns the path to the OONI Home
|
||||
func GetOONIHome() (string, error) {
|
||||
if ooniHome := os.Getenv("OONI_HOME"); ooniHome != "" {
|
||||
|
|
@ -96,8 +74,5 @@ func DidLegacyInformedConsent() bool {
|
|||
}
|
||||
|
||||
path := filepath.Join(filepath.Join(home, ".ooni"), "initialized")
|
||||
if FileExists(path) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return FileExists(path)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue