Skip to content

Commit 32d1449

Browse files
committed
Use more appropriate directory folders for config.ini
1 parent fd31f87 commit 32d1449

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

config.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2023 Arduino SA
2+
//
3+
// This program is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU Affero General Public License as published
5+
// by the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// This program is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU Affero General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU Affero General Public License
14+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
15+
16+
package main
17+
18+
import (
19+
"fmt"
20+
"os"
21+
22+
"github.com/arduino/go-paths-helper"
23+
)
24+
25+
// getDefaultArduinoCreateConfigDir returns the full path to the default arduino create agent data directory
26+
func getDefaultArduinoCreateConfigDir() (*paths.Path, error) {
27+
// UserConfigDir returns the default root directory to use
28+
// for user-specific configuration data. Users should create
29+
// their own application-specific subdirectory within this
30+
// one and use that.
31+
//
32+
// On Unix systems, it returns $XDG_CONFIG_HOME as specified by
33+
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
34+
// if non-empty, else $HOME/.config.
35+
//
36+
// On Darwin, it returns $HOME/Library/Application Support.
37+
// On Windows, it returns %AppData%.
38+
// On Plan 9, it returns $home/lib.
39+
//
40+
// If the location cannot be determined (for example, $HOME
41+
// is not defined), then it will return an error.
42+
configDir, err := os.UserConfigDir()
43+
if err != nil {
44+
return nil, err
45+
}
46+
47+
agentConfigDir := paths.New(configDir, "ArduinoCreateAgent")
48+
if err := agentConfigDir.MkdirAll(); err != nil {
49+
return nil, fmt.Errorf("cannot create config dir: %s", err)
50+
}
51+
return agentConfigDir, nil
52+
}

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/andela/gin-cors v0.0.0-20160928171741-e8c3436a37e2
77
github.com/arduino/arduino-cli v0.0.0-20210422154105-5aa424818026
88
github.com/arduino/go-paths-helper v1.8.0
9+
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b
910
github.com/blang/semver v3.5.1+incompatible
1011
github.com/codeclysm/extract/v3 v3.1.0
1112
github.com/getlantern/systray v1.1.0

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ github.com/arduino/go-paths-helper v1.8.0 h1:BfA1bq1XktnlqwfUDCoKbUqB3YFPe6X7szP
1919
github.com/arduino/go-paths-helper v1.8.0/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
2020
github.com/arduino/go-properties-orderedmap v1.3.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
2121
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b/go.mod h1:uwGy5PpN4lqW97FiLnbcx+xx8jly5YuPMJWfVwwjJiQ=
22+
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b h1:3PjgYG5gVPA7cipp7vIR2lF96KkEJIFBJ+ANnuv6J20=
2223
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b/go.mod h1:iIPnclBMYm1g32Q5kXoqng4jLhMStReIP7ZxaoUC2y8=
2324
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
2425
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=

main.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"flag"
2525
"io/ioutil"
2626
"os"
27-
"os/user"
2827
"runtime"
2928
"runtime/debug"
3029
"strconv"
@@ -192,9 +191,7 @@ func loop() {
192191
src, _ := os.Executable()
193192
srcPath := paths.New(src) // The path of the agent's binary
194193
srcDir := srcPath.Parent() // The directory of the agent's binary
195-
usr, _ := user.Current()
196-
usrDir := paths.New(usr.HomeDir) // The user folder, on linux/macos /home/<usr>/
197-
agentDir := usrDir.Join(".arduino-create")
194+
agentDir, err := getDefaultArduinoCreateConfigDir()
198195

199196
// Instantiate Tools
200197
Tools = tools.Tools{

0 commit comments

Comments
 (0)