Skip to content

Commit 54db5f9

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

File tree

4 files changed

+52
-4
lines changed

4 files changed

+52
-4
lines changed

config.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
"runtime"
22+
23+
"github.com/arduino/go-paths-helper"
24+
"github.com/arduino/go-win32-utils"
25+
)
26+
27+
// getDefaultArduinoCreateDataDir returns the full path to the default arduino create agent data directory
28+
func getDefaultArduinoCreateDataDir() (*paths.Path, error) {
29+
userHomeDir, err := os.UserHomeDir()
30+
if err != nil {
31+
return nil, err
32+
}
33+
34+
switch runtime.GOOS {
35+
case "linux":
36+
return paths.New(userHomeDir, ".arduino-create-agent"), nil
37+
case "darwin":
38+
return paths.New(userHomeDir, "Library", "ArduinoCreateAgent"), nil
39+
case "windows":
40+
localAppDataPath, err := win32.GetLocalAppDataFolder()
41+
if err != nil {
42+
return nil, fmt.Errorf("unable to get Local App Data Folder: %w", err)
43+
}
44+
return paths.New(localAppDataPath, "ArduinoCreateAgent"), nil
45+
default:
46+
log.Panicf("unsupported OS: %s", runtime.GOOS)
47+
return nil, nil // unreachable
48+
}
49+
}

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 := getDefaultArduinoCreateDataDir()
198195

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

0 commit comments

Comments
 (0)