telemetry: create ~/.config/dagger directory if it doesn't exit

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi 2022-03-08 23:31:38 -08:00
parent c17ce97381
commit 3d06252858

View File

@ -4,8 +4,10 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"net/http"
"os"
"path/filepath"
"runtime"
"time"
@ -147,6 +149,14 @@ func getDeviceID() (string, error) {
}
id, err := os.ReadFile(idFile)
if err != nil {
if !errors.Is(err, os.ErrNotExist) {
return "", err
}
if err := os.MkdirAll(filepath.Dir(idFile), 0755); err != nil {
return "", err
}
id = []byte(uuid.New().String())
if err := os.WriteFile(idFile, id, 0600); err != nil {
return "", err