Skip to content

Commit 46ff1ea

Browse files
committed
Added method to directly get data-dir
1 parent 2d13789 commit 46ff1ea

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ import (
2323
log "github.com/sirupsen/logrus"
2424
)
2525

26+
// getDataDir returns the full path to the default Arduino Create Agent data directory.
27+
func getDataDir() *paths.Path {
28+
userDir, err := os.UserHomeDir()
29+
if err != nil {
30+
log.Panicf("Could not get user dir: %s", err)
31+
}
32+
dataDir := paths.New(userDir, ".arduino-create")
33+
if err := dataDir.MkdirAll(); err != nil {
34+
log.Panicf("Could not create data dir: %s", err)
35+
}
36+
return dataDir
37+
}
38+
2639
// getDefaultConfigDir returns the full path to the default Arduino Create Agent configuration directory.
2740
func getDefaultConfigDir() *paths.Path {
2841
// UserConfigDir returns the default root directory to use

main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,10 @@ func loop() {
192192
src, _ := os.Executable()
193193
srcPath := paths.New(src) // The path of the agent's binary
194194
srcDir := srcPath.Parent() // The directory of the agent's binary
195-
agentDir := getDefaultConfigDir()
196195

197196
// Instantiate Tools
198197
Tools = tools.Tools{
199-
Directory: agentDir.String(),
198+
Directory: getDataDir().String(),
200199
IndexURL: *indexURL,
201200
Logger: func(msg string) {
202201
mapD := map[string]string{"DownloadStatus": "Pending", "Msg": msg}
@@ -407,7 +406,7 @@ func loop() {
407406
r.POST("/update", updateHandler)
408407

409408
// Mount goa handlers
410-
goa := v2.Server(agentDir.String())
409+
goa := v2.Server(getDataDir().String())
411410
r.Any("/v2/*path", gin.WrapH(goa))
412411

413412
go func() {

0 commit comments

Comments
 (0)