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:
DecFox 2022-11-15 15:05:30 +05:30 committed by GitHub
commit 6b01264373
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 53 additions and 56 deletions

View file

@ -0,0 +1,29 @@
package database
import (
"errors"
"fmt"
"os"
"path/filepath"
"time"
)
// 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
}