mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
core: use stdlib for xdg dirs
This commit is contained in:
@@ -20,33 +20,3 @@ func ExpandPath(path string) (string, error) {
|
||||
|
||||
return expanded, nil
|
||||
}
|
||||
|
||||
func XDGConfigHome() string {
|
||||
if configHome := os.Getenv("XDG_CONFIG_HOME"); configHome != "" {
|
||||
return configHome
|
||||
}
|
||||
if home, err := os.UserHomeDir(); err == nil {
|
||||
return filepath.Join(home, ".config")
|
||||
}
|
||||
return filepath.Join(os.TempDir(), ".config")
|
||||
}
|
||||
|
||||
func XDGCacheHome() string {
|
||||
if cacheHome := os.Getenv("XDG_CACHE_HOME"); cacheHome != "" {
|
||||
return cacheHome
|
||||
}
|
||||
if home, err := os.UserHomeDir(); err == nil {
|
||||
return filepath.Join(home, ".cache")
|
||||
}
|
||||
return filepath.Join(os.TempDir(), ".cache")
|
||||
}
|
||||
|
||||
func XDGDataHome() string {
|
||||
if dataHome := os.Getenv("XDG_DATA_HOME"); dataHome != "" {
|
||||
return dataHome
|
||||
}
|
||||
if home, err := os.UserHomeDir(); err == nil {
|
||||
return filepath.Join(home, ".local", "share")
|
||||
}
|
||||
return filepath.Join(os.TempDir(), ".local", "share")
|
||||
}
|
||||
|
||||
@@ -41,66 +41,3 @@ func TestExpandPathAbsolute(t *testing.T) {
|
||||
t.Errorf("expected /absolute/path, got %s", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXDGConfigHomeDefault(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", "")
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Skip("no home directory")
|
||||
}
|
||||
result := XDGConfigHome()
|
||||
expected := filepath.Join(home, ".config")
|
||||
if result != expected {
|
||||
t.Errorf("expected %s, got %s", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXDGConfigHomeCustom(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", "/custom/config")
|
||||
result := XDGConfigHome()
|
||||
if result != "/custom/config" {
|
||||
t.Errorf("expected /custom/config, got %s", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXDGCacheHomeDefault(t *testing.T) {
|
||||
t.Setenv("XDG_CACHE_HOME", "")
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Skip("no home directory")
|
||||
}
|
||||
result := XDGCacheHome()
|
||||
expected := filepath.Join(home, ".cache")
|
||||
if result != expected {
|
||||
t.Errorf("expected %s, got %s", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXDGCacheHomeCustom(t *testing.T) {
|
||||
t.Setenv("XDG_CACHE_HOME", "/custom/cache")
|
||||
result := XDGCacheHome()
|
||||
if result != "/custom/cache" {
|
||||
t.Errorf("expected /custom/cache, got %s", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXDGDataHomeDefault(t *testing.T) {
|
||||
t.Setenv("XDG_DATA_HOME", "")
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
t.Skip("no home directory")
|
||||
}
|
||||
result := XDGDataHome()
|
||||
expected := filepath.Join(home, ".local", "share")
|
||||
if result != expected {
|
||||
t.Errorf("expected %s, got %s", expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestXDGDataHomeCustom(t *testing.T) {
|
||||
t.Setenv("XDG_DATA_HOME", "/custom/data")
|
||||
result := XDGDataHome()
|
||||
if result != "/custom/data" {
|
||||
t.Errorf("expected /custom/data, got %s", result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user