This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathappdirs_unix.go
102 lines (75 loc) · 2.08 KB
/
appdirs_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// +build linux freebsd netbsd openbsd
package appdirs
import (
"os"
"path/filepath"
)
func userDataDir(name, author, version string, roaming bool) (path string) {
if path = os.Getenv("XDG_DATA_HOME"); path == "" {
path = ExpandUser("~/.local/share")
}
if name != "" {
path = filepath.Join(path, name, version)
}
return path
}
func SiteDataDirs(name, author, version string) (paths []string) {
var path string
if path = os.Getenv("XDG_DATA_DIRS"); path == "" {
paths = []string{"/usr/local/share", "/usr/share"}
} else {
paths = filepath.SplitList(path)
}
for i, path := range paths {
path = ExpandUser(path)
if name != "" {
path = filepath.Join(path, name, version)
}
paths[i] = path
}
return paths
}
func siteDataDir(name, author, version string) (path string) {
return SiteDataDirs(name, author, version)[0]
}
func userConfigDir(name, author, version string, roaming bool) (path string) {
if path = os.Getenv("XDG_CONFIG_HOME"); path == "" {
path = ExpandUser("~/.config")
}
if name != "" {
path = filepath.Join(path, name, version)
}
return path
}
func SiteConfigDirs(name, author, version string) (paths []string) {
var path string
if path = os.Getenv("XDG_CONFIG_DIRS"); path == "" {
paths = []string{"/etc/xdg"}
} else {
paths = filepath.SplitList(path)
}
for i, path := range paths {
path = ExpandUser(path)
if name != "" {
path = filepath.Join(path, name, version)
}
paths[i] = path
}
return paths
}
func siteConfigDir(name, author, version string) (path string) {
return SiteConfigDirs(name, author, version)[0]
}
func userCacheDir(name, author, version string, opinion bool) (path string) {
if path = os.Getenv("XDG_CACHE_HOME"); path == "" {
path = ExpandUser("~/.cache")
}
if name != "" {
path = filepath.Join(path, name, version)
}
return path
}
func userLogDir(name, author, version string, opinion bool) (path string) {
path = UserCacheDir(name, author, version, opinion)
return filepath.Join(path, "log")
}