Browse Source

Remove basedir implementation

Go added native support for finding the config directory via
`os.UserConfigDir()`, so no need for a custom implementation with the
potantial of becomming outdated/wrong over time.
pull/71/head
j.r 3 years ago
parent
commit
ab9f898869
No known key found for this signature in database
GPG Key ID: E74A18B933F9145E
  1. 35
      basedir/basedir.go
  2. 6
      basedir/basedir_darwin.go
  3. 8
      basedir/basedir_unix.go
  4. 6
      basedir/basedir_windows.go
  5. 8
      main.go

35
basedir/basedir.go

@ -1,35 +0,0 @@
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
// See LICENSE for licensing information
package basedir
import (
"os"
"os/user"
"path/filepath"
)
// TODO: replace with https://github.com/golang/go/issues/29960 if accepted.
// Data returns the base data directory.
func Data() string {
return dataDir
}
func firstGetenv(def string, evs ...string) string {
for _, ev := range evs {
if v := os.Getenv(ev); v != "" {
return v
}
}
// TODO: replace with os.UserHomeDir once we require Go 1.12 or later.
home := os.Getenv("HOME")
if home == "" {
curUser, err := user.Current()
if err != nil {
return ""
}
home = curUser.HomeDir
}
return filepath.Join(home, def)
}

6
basedir/basedir_darwin.go

@ -1,6 +0,0 @@
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
// See LICENSE for licensing information
package basedir
var dataDir = firstGetenv("Library/Application Support")

8
basedir/basedir_unix.go

@ -1,8 +0,0 @@
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
// See LICENSE for licensing information
// +build dragonfly freebsd linux netbsd openbsd
package basedir
var dataDir = firstGetenv(".config", "XDG_CONFIG_HOME")

6
basedir/basedir_windows.go

@ -1,6 +0,0 @@
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
// See LICENSE for licensing information
package basedir
var dataDir = firstGetenv("", "APPDATA")

8
main.go

@ -10,8 +10,6 @@ import (
"os"
"path/filepath"
"strings"
"mvdan.cc/fdroidcl/basedir"
)
const cmdName = "fdroidcl"
@ -36,9 +34,9 @@ func mustCache() string {
}
func mustData() string {
dir := basedir.Data()
if dir == "" {
fmt.Fprintln(os.Stderr, "Could not determine data dir")
dir, err := os.UserConfigDir()
if err != nil {
fmt.Fprintln(os.Stderr, err)
panic("TODO: return an error")
}
return subdir(dir, cmdName)

Loading…
Cancel
Save