@@ -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+
3040func 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 {
96106func 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 ()})
0 commit comments