save result of os.Getenv and use that if possible to reduce some syscalls
This commit is contained in:
38
tools.go
38
tools.go
@@ -121,11 +121,11 @@ func getUserDir(home, line string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cacheDir() string {
|
func cacheDir() string {
|
||||||
if os.Getenv("XDG_CACHE_HOME") != "" {
|
if xdgCache := os.Getenv("XDG_CACHE_HOME"); xdgCache != "" {
|
||||||
return os.Getenv("XDG_CONFIG_HOME")
|
return xdgCache
|
||||||
}
|
}
|
||||||
if os.Getenv("HOME") != "" && pathExists(filepath.Join(os.Getenv("HOME"), ".cache")) {
|
if home := os.Getenv("HOME"); home != "" && pathExists(filepath.Join(home, ".cache")) {
|
||||||
p := filepath.Join(os.Getenv("HOME"), ".cache")
|
p := filepath.Join(home, ".cache")
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
@@ -141,11 +141,11 @@ func readTextFile(path string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func oldConfigDir() (string, error) {
|
func oldConfigDir() (string, error) {
|
||||||
if os.Getenv("XDG_CONFIG_HOME") != "" {
|
if xdgConfig := os.Getenv("XDG_CONFIG_HOME"); xdgConfig != "" {
|
||||||
dir := path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-panel")
|
dir := path.Join(xdgConfig, "nwg-panel")
|
||||||
return dir, nil
|
return dir, nil
|
||||||
} else if os.Getenv("HOME") != "" {
|
} else if home := os.Getenv("HOME"); home != "" {
|
||||||
dir := path.Join(os.Getenv("HOME"), ".config/nwg-panel")
|
dir := path.Join(home, ".config/nwg-panel")
|
||||||
return dir, nil
|
return dir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,10 +154,10 @@ func oldConfigDir() (string, error) {
|
|||||||
|
|
||||||
func configDir() string {
|
func configDir() string {
|
||||||
var dir string
|
var dir string
|
||||||
if os.Getenv("XDG_CONFIG_HOME") != "" {
|
if xdgConfig := os.Getenv("XDG_CONFIG_HOME"); xdgConfig != "" {
|
||||||
dir = path.Join(os.Getenv("XDG_CONFIG_HOME"), "nwg-drawer")
|
dir = path.Join(xdgConfig, "nwg-drawer")
|
||||||
} else if os.Getenv("HOME") != "" {
|
} else if home := os.Getenv("HOME"); home != "" {
|
||||||
dir = path.Join(os.Getenv("HOME"), ".config/nwg-drawer")
|
dir = path.Join(home, ".config/nwg-drawer")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Config dir: %s", dir)
|
log.Infof("Config dir: %s", dir)
|
||||||
@@ -168,10 +168,10 @@ func configDir() string {
|
|||||||
|
|
||||||
func dataDir() string {
|
func dataDir() string {
|
||||||
var dir string
|
var dir string
|
||||||
if os.Getenv("XDG_DATA_HOME") != "" {
|
if xdgData := os.Getenv("XDG_DATA_HOME"); xdgData != "" {
|
||||||
dir = path.Join(os.Getenv("XDG_DATA_HOME"), "nwg-drawer")
|
dir = path.Join(xdgData, "nwg-drawer")
|
||||||
} else if os.Getenv("HOME") != "" {
|
} else if home := os.Getenv("HOME"); home != "" {
|
||||||
dir = path.Join(os.Getenv("HOME"), ".local/share/nwg-drawer")
|
dir = path.Join(home, ".local/share/nwg-drawer")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Data dir: %s", dir)
|
log.Infof("Data dir: %s", dir)
|
||||||
@@ -228,13 +228,11 @@ func copyFile(src, dst string) error {
|
|||||||
|
|
||||||
func getAppDirs() []string {
|
func getAppDirs() []string {
|
||||||
var dirs []string
|
var dirs []string
|
||||||
xdgDataDirs := ""
|
|
||||||
|
|
||||||
home := os.Getenv("HOME")
|
home := os.Getenv("HOME")
|
||||||
xdgDataHome := os.Getenv("XDG_DATA_HOME")
|
xdgDataHome := os.Getenv("XDG_DATA_HOME")
|
||||||
if os.Getenv("XDG_DATA_DIRS") != "" {
|
xdgDataDirs := os.Getenv("XDG_DATA_DIRS")
|
||||||
xdgDataDirs = os.Getenv("XDG_DATA_DIRS")
|
if xdgDataDirs == "" {
|
||||||
} else {
|
|
||||||
xdgDataDirs = "/usr/local/share/:/usr/share/"
|
xdgDataDirs = "/usr/local/share/:/usr/share/"
|
||||||
}
|
}
|
||||||
if xdgDataHome != "" {
|
if xdgDataHome != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user