Skip to content

Commit 641bf62

Browse files
committed
Move all .local content
1 parent 4b137ac commit 641bf62

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

debian/arduino-app-cli/DEBIAN/postinst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/sh
22

3-
chown -R arduino:arduino /home/arduino/.local/share/arduino-app-cli
3+
#chown -R arduino:arduino /home/arduino/.local/share/arduino-app-cli
44
mkdir /var/cache/arduino-app-cli
55
chown -R arduino:arduino /var/cache/arduino-app-cli
6+
mkdir /home/arduino/.arduino-app-cli
7+
chown -R arduino:arduino /home/arduino/.arduino-app-cli
68

79
systemctl enable arduino-app-cli
810
systemctl enable arduino-burn-bootloader
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/sh
22

3+
# TODO delete /var/cache
4+
rm -rf /var/cache/arduino-app-cli
5+
36
if [ -d /run/systemd/system ]; then
47
systemctl daemon-reload
58
fi
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/bin/sh
22

3-
# TODO cache should be invalidated
4-
53
systemctl disable arduino-app-cli
64
systemctl disable arduino-burn-bootloader
75
systemctl disable arduino-avahi-serial.service

internal/api/handlers/properties.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,26 @@ import (
2020
"io"
2121
"log/slog"
2222
"net/http"
23+
"os"
2324

2425
"github.com/arduino/arduino-app-cli/internal/api/models"
2526
"github.com/arduino/arduino-app-cli/internal/orchestrator/config"
2627
properties "github.com/arduino/arduino-app-cli/internal/orchestrator/system_properties"
2728
"github.com/arduino/arduino-app-cli/internal/render"
29+
"github.com/arduino/go-paths-helper"
2830
)
2931

32+
func getPropertiesDir() string {
33+
xdgHome, _ := os.UserHomeDir()
34+
//if err != nil {
35+
// slog.Error("Unable to retrieve list", slog.String("error", err.Error()))
36+
//}
37+
return paths.New(xdgHome).Join(".arduino-app-cli", "properties.msgpack").String()
38+
}
39+
3040
func HandlePropertyKeys(cfg config.Configuration) http.HandlerFunc {
3141
return func(w http.ResponseWriter, r *http.Request) {
32-
propertyList, err := properties.ReadPropertyKeys(cfg.DataDir().Join("properties.msgpack").String())
42+
propertyList, err := properties.ReadPropertyKeys(getPropertiesDir())
3343
if err != nil {
3444
slog.Error("Unable to retrieve list", slog.String("error", err.Error()))
3545
render.EncodeResponse(w, http.StatusInternalServerError, models.ErrorResponse{Details: "unable to find the list"})
@@ -43,7 +53,7 @@ func HandlePropertyGet(cfg config.Configuration) http.HandlerFunc {
4353
return func(w http.ResponseWriter, r *http.Request) {
4454
key := r.PathValue("key")
4555

46-
property, found, err := properties.GetProperty(cfg.DataDir().Join("properties.msgpack").String(), key)
56+
property, found, err := properties.GetProperty(getPropertiesDir(), key)
4757
if err != nil {
4858
if errors.Is(err, properties.ErrInvalidKey) {
4959
render.EncodeResponse(w, http.StatusBadRequest, models.ErrorResponse{Details: err.Error()})
@@ -79,7 +89,7 @@ func HandlePropertyUpsert(cfg config.Configuration) http.HandlerFunc {
7989
return
8090
}
8191

82-
err = properties.UpsertProperty(cfg.DataDir().Join("properties.msgpack").String(), key, reqBody)
92+
err = properties.UpsertProperty(getPropertiesDir(), key, reqBody)
8393
if err != nil {
8494
if errors.Is(err, properties.ErrInvalidKey) {
8595
render.EncodeResponse(w, http.StatusBadRequest, models.ErrorResponse{Details: err.Error()})
@@ -96,7 +106,7 @@ func HandlePropertyUpsert(cfg config.Configuration) http.HandlerFunc {
96106
func HandlePropertyDelete(cfg config.Configuration) http.HandlerFunc {
97107
return func(w http.ResponseWriter, r *http.Request) {
98108
key := r.PathValue("key")
99-
found, err := properties.DeleteProperty(cfg.DataDir().Join("properties.msgpack").String(), key)
109+
found, err := properties.DeleteProperty(getPropertiesDir(), key)
100110
if err != nil {
101111
if errors.Is(err, properties.ErrInvalidKey) {
102112
render.EncodeResponse(w, http.StatusBadRequest, models.ErrorResponse{Details: err.Error()})

internal/orchestrator/app/app.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"encoding/hex"
2121
"errors"
2222
"fmt"
23-
"log/slog"
2423
"os"
2524
"path/filepath"
2625

@@ -150,7 +149,6 @@ func (a *ArduinoApp) SketchBuildPath() *paths.Path {
150149
func (a *ArduinoApp) ProvisioningStateDir() *paths.Path {
151150
cachePath := filepath.Join("/", "var", "cache", "arduino-app-cli")
152151
hash := md5.Sum([]byte(a.FullPath.String()))
153-
slog.Error("Provision for %s to %s", a.FullPath.String(), paths.New(filepath.Join(cachePath, hex.EncodeToString((hash[:])), ".cache")).String())
154152
return paths.New(filepath.Join(cachePath, hex.EncodeToString((hash[:])), ".cache"))
155153
}
156154

internal/orchestrator/config/config.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package config
1717

1818
import (
19+
"errors"
1920
"fmt"
2021
"log/slog"
2122
"net/url"
@@ -62,11 +63,13 @@ func NewFromEnv() (Configuration, error) {
6263

6364
dataDir := paths.New(os.Getenv("ARDUINO_APP_CLI__DATA_DIR"))
6465
if dataDir == nil {
65-
xdgHome, err := os.UserHomeDir()
66-
if err != nil {
67-
return Configuration{}, err
66+
dataDir = paths.New("/", "usr", "share", "arduino-app-cli")
67+
slog.Info("ARDUINO_APP_CLI__DATA_DIR unset, use default", slog.String("ARDUINO_APP_CLI__DATA_DIR", dataDir.String()))
68+
if dataDir == nil {
69+
return Configuration{}, errors.New("unable to create data dir")
6870
}
69-
dataDir = paths.New(xdgHome).Join(".local", "share", "arduino-app-cli")
71+
} else {
72+
slog.Info("ARDUINO_APP_CLI__DATA_DIR override", slog.String("ARDUINO_APP_CLI__DATA_DIR", dataDir.String()))
7073
}
7174

7275
routerSocket := paths.New(os.Getenv("ARDUINO_ROUTER_SOCKET"))

0 commit comments

Comments
 (0)