mirror of https://github.com/mvdan/fdroidcl.git
Browse Source
I have been moving all github.com/mvdan/... packages to mvdan.cc/... recently - do this one too. basedir was only really used by these packages, so merge it in to simplify building and packaging the tool.pull/32/head
15 changed files with 110 additions and 14 deletions
@ -0,0 +1,41 @@
|
||||
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
|
||||
// See LICENSE for licensing information
|
||||
|
||||
package basedir |
||||
|
||||
import ( |
||||
"os" |
||||
"os/user" |
||||
"path/filepath" |
||||
) |
||||
|
||||
// Cache returns the base cache directory.
|
||||
func Cache() string { |
||||
return cache() |
||||
} |
||||
|
||||
// Data returns the base data directory.
|
||||
func Data() string { |
||||
return data() |
||||
} |
||||
|
||||
func firstGetenv(def string, evs ...string) string { |
||||
for _, ev := range evs { |
||||
if v := os.Getenv(ev); v != "" { |
||||
return v |
||||
} |
||||
} |
||||
home, err := homeDir() |
||||
if err != nil { |
||||
return "" |
||||
} |
||||
return filepath.Join(home, def) |
||||
} |
||||
|
||||
func homeDir() (string, error) { |
||||
curUser, err := user.Current() |
||||
if err != nil { |
||||
return "", err |
||||
} |
||||
return curUser.HomeDir, nil |
||||
} |
||||
@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
|
||||
// See LICENSE for licensing information
|
||||
|
||||
package basedir |
||||
|
||||
var ( |
||||
cacheDir = firstGetenv("Library/Caches") |
||||
dataDir = firstGetenv("Library/Application Support") |
||||
) |
||||
|
||||
func cache() string { |
||||
return cacheDir |
||||
} |
||||
|
||||
func data() string { |
||||
return dataDir |
||||
} |
||||
@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
|
||||
// See LICENSE for licensing information
|
||||
|
||||
// +build dragonfly freebsd linux netbsd openbsd
|
||||
|
||||
package basedir |
||||
|
||||
var ( |
||||
cacheDir = firstGetenv(".cache", "XDG_CACHE_HOME") |
||||
dataDir = firstGetenv(".config", "XDG_CONFIG_HOME") |
||||
) |
||||
|
||||
func cache() string { |
||||
return cacheDir |
||||
} |
||||
|
||||
func data() string { |
||||
return dataDir |
||||
} |
||||
@ -0,0 +1,17 @@
|
||||
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
|
||||
// See LICENSE for licensing information
|
||||
|
||||
package basedir |
||||
|
||||
var ( |
||||
cacheDir = firstGetenv("", "TEMP", "TMP") |
||||
dataDir = firstGetenv("", "APPDATA") |
||||
) |
||||
|
||||
func cache() string { |
||||
return cacheDir |
||||
} |
||||
|
||||
func data() string { |
||||
return dataDir |
||||
} |
||||
Loading…
Reference in new issue