Skip to content

Commit

Permalink
Modified config to utilize the os.UserHomeDir() vs user.Current().Hom…
Browse files Browse the repository at this point in the history
…eDir (#52)

* Update config.go

Modify config.go to use os.UserHomeDir() function which supports env variables vs mandating CurrentUser

* Update config.go

Modifed to use the os.UserHomeDir() function to take into consideration user's ENV variables, and XDG Base Directory Specification
  • Loading branch information
ZacWolf authored Mar 16, 2021
1 parent 755c209 commit be73ea5
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io"
"os"
"os/user"
"path/filepath"
"runtime"

Expand All @@ -29,9 +28,8 @@ type Binary struct {
}

func CheckAndLoad() error {
u, _ := user.Current()

configDir := filepath.Join(u.HomeDir, ".bin")
home, err := os.UserHomeDir()
configDir := filepath.Join(home, ".bin")

if err := os.Mkdir(configDir, 0755); err != nil && !os.IsExist(err) {
return fmt.Errorf("Error creating config directory [%v]", err)
Expand Down Expand Up @@ -99,8 +97,8 @@ func RemoveBinaries(paths []string) error {
}

func write() error {
u, _ := user.Current()
f, err := os.OpenFile(filepath.Join(u.HomeDir, ".bin", "config.json"), os.O_RDWR|os.O_CREATE, 0666)
home, err := os.UserHomeDir()
f, err := os.OpenFile(filepath.Join(home, ".bin", "config.json"), os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
return err
}
Expand Down

0 comments on commit be73ea5

Please sign in to comment.