Skip to content

Cleanup directories handling #765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added method to directly get data-dir
  • Loading branch information
cmaglie committed Feb 10, 2023
commit 46ff1eab1d1ba4ede7146a1cb669a1f6c0d6073e
13 changes: 13 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ import (
log "github.com/sirupsen/logrus"
)

// getDataDir returns the full path to the default Arduino Create Agent data directory.
func getDataDir() *paths.Path {
userDir, err := os.UserHomeDir()
if err != nil {
log.Panicf("Could not get user dir: %s", err)
}
dataDir := paths.New(userDir, ".arduino-create")
if err := dataDir.MkdirAll(); err != nil {
log.Panicf("Could not create data dir: %s", err)
}
return dataDir
}

// getDefaultConfigDir returns the full path to the default Arduino Create Agent configuration directory.
func getDefaultConfigDir() *paths.Path {
// UserConfigDir returns the default root directory to use
Expand Down
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,10 @@ func loop() {
src, _ := os.Executable()
srcPath := paths.New(src) // The path of the agent's binary
srcDir := srcPath.Parent() // The directory of the agent's binary
agentDir := getDefaultConfigDir()

// Instantiate Tools
Tools = tools.Tools{
Directory: agentDir.String(),
Directory: getDataDir().String(),
IndexURL: *indexURL,
Logger: func(msg string) {
mapD := map[string]string{"DownloadStatus": "Pending", "Msg": msg}
Expand Down Expand Up @@ -407,7 +406,7 @@ func loop() {
r.POST("/update", updateHandler)

// Mount goa handlers
goa := v2.Server(agentDir.String())
goa := v2.Server(getDataDir().String())
r.Any("/v2/*path", gin.WrapH(goa))

go func() {
Expand Down