-
Notifications
You must be signed in to change notification settings - Fork 0
/
dir_darwin.go
118 lines (90 loc) · 2 KB
/
dir_darwin.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package appdirs
import (
"os"
"os/user"
"path"
"strings"
)
func homeDir() (string, error) {
// first check for the $HOME var
if os.Getenv("HOME") != "" {
return os.Getenv("HOME"), nil
}
// otherwise retrieve from the user
usr, err := user.Current()
if err != nil {
return "", err
}
return usr.HomeDir, nil
}
func expandDir(dir string) (string, error) {
if !strings.HasPrefix(dir, "~/") {
return dir, nil
}
home, err := homeDir()
if err != nil {
return "", err
}
return path.Join(home, dir[2:]), nil
}
func (conf AppConf) userDataDir() (string, error) {
home, err := HomeDir()
if err != nil {
return "", err
}
dataHome = path.Join(home, "Library/Application Support")
// add app information
if conf.Name != "" {
dataHome = path.Join(dataHome, conf.Name)
if conf.Version != "" {
dataHome = path.Join(dataHome, conf.Version)
}
}
return dataHome, nil
}
func (conf AppConf) siteDataDir() (string, error) {
dataDir := "/Library/Application Support"
if conf.Name != "" {
dataDir = path.Join(dataDir, conf.Name)
if conf.Version != "" {
dataDir = path.Join(dataDir, conf.Version)
}
}
return dataDir, nil
}
func (conf AppConf) userConfigDir() (string, error) {
return conf.userDataDir()
}
func (conf AppConf) siteConfigDir() (string, error) {
return conf.siteDataDir()
}
func (conf AppConf) userCacheDir() (string, error) {
home, err := HomeDir()
if err != nil {
return "", err
}
cacheDir = path.Join(home, "Library/Caches")
// add app information
if conf.Name != "" {
cacheDir = path.Join(cacheDir, conf.Name)
if conf.Version != "" {
cacheDir = path.Join(cacheDir, conf.Version)
}
}
return cacheDir, nil
}
func (conf AppConf) userLogDir() (string, error) {
home, err := HomeDir()
if err != nil {
return "", err
}
logDir = path.Join(home, "Library/Logs")
// add app information
if conf.Name != "" {
logDir = path.Join(logDir, conf.Name)
if conf.Version != "" {
logDir = path.Join(logDir, conf.Version)
}
}
return logDir, nil
}