Skip to content
This repository has been archived by the owner on Jan 12, 2025. It is now read-only.

Commit

Permalink
Merge pull request #58 from ok-borg/fix-56
Browse files Browse the repository at this point in the history
Fix #56, do not use user package as it relies on cgo
  • Loading branch information
crufter authored Mar 14, 2017
2 parents 47376a0 + f08f4b7 commit 57ee9c7
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package conf
import (
"io/ioutil"
"os"
"os/user"
"path/filepath"

flag "github.com/juju/gnuflag"
Expand Down Expand Up @@ -63,20 +62,18 @@ func init() {
}

func borgDir() string {
usr, err := user.Current()
if err != nil {
panic(err)
home := os.Getenv("HOME")
if len(home) == 0 {
panic("$HOME environment variable is not set")
}
dir := filepath.Join(usr.HomeDir, ".borg")

dir := filepath.Join(home, ".borg")
if _, err := os.Stat(dir); os.IsNotExist(err) {
if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" {
dir = filepath.Join(xdgConfigHome, "borg")
} else {
dir = filepath.Join(os.Getenv("HOME"), ".config")
dir = filepath.Join(home, ".config")
}
}

return dir
}

Expand All @@ -94,12 +91,12 @@ func (c Config) Save() error {
if err != nil {
return err
}
return ioutil.WriteFile(QueryFile, bs, os.ModePerm)
return ioutil.WriteFile(ConfigFile, bs, os.ModePerm)
}

// Get config
func Get() (Config, error) {
bs, err := ioutil.ReadFile(QueryFile)
bs, err := ioutil.ReadFile(ConfigFile)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 57ee9c7

Please sign in to comment.