Skip to content

Use $HOME environment for user's home directory first #169

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
39 changes: 23 additions & 16 deletions configs/directories.go
Original file line number Diff line number Diff line change
@@ -19,20 +19,32 @@ package configs

import (
"fmt"
"os"
"os/user"
"runtime"

"github.com/arduino/go-paths-helper"
"github.com/arduino/go-win32-utils"
)

// getUserHomeDir returns user's home directory from $HOME or then from os/user
func getUserHomeDir() string {
home := os.Getenv("HOME")
if home == "" {
usr, err := user.Current()
if err != nil {
panic(fmt.Errorf("retrieving user home dir: %s", err))
}
home = usr.HomeDir
}
return home
}

// getDefaultConfigFilePath returns the default path for arduino-cli.yaml
func getDefaultConfigFilePath() *paths.Path {
usr, err := user.Current()
if err != nil {
panic(fmt.Errorf("retrieving user home dir: %s", err))
}
arduinoDataDir := paths.New(usr.HomeDir)
userHomeDir := getUserHomeDir()

arduinoDataDir := paths.New(userHomeDir)

switch runtime.GOOS {
case "linux":
@@ -53,11 +65,9 @@ func getDefaultConfigFilePath() *paths.Path {
}

func getDefaultArduinoDataDir() (*paths.Path, error) {
usr, err := user.Current()
if err != nil {
return nil, fmt.Errorf("retrieving user home dir: %s", err)
}
arduinoDataDir := paths.New(usr.HomeDir)
userHomeDir := getUserHomeDir()

arduinoDataDir := paths.New(userHomeDir)

switch runtime.GOOS {
case "linux":
@@ -77,16 +87,13 @@ func getDefaultArduinoDataDir() (*paths.Path, error) {
}

func getDefaultSketchbookDir() (*paths.Path, error) {
usr, err := user.Current()
if err != nil {
return nil, fmt.Errorf("retrieving home dir: %s", err)
}
userHomeDir := getUserHomeDir()

switch runtime.GOOS {
case "linux":
return paths.New(usr.HomeDir).Join("Arduino"), nil
return paths.New(userHomeDir).Join("Arduino"), nil
case "darwin":
return paths.New(usr.HomeDir).Join("Documents", "Arduino"), nil
return paths.New(userHomeDir).Join("Documents", "Arduino"), nil
case "windows":
documentsPath, err := win32.GetDocumentsFolder()
if err != nil {