-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxdgbasedir_darwin.go
76 lines (64 loc) · 1.85 KB
/
xdgbasedir_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
// Copyright 2017 The go-xdgbasedir Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin
package xdgbasedir
import (
"os"
"path/filepath"
"strconv"
"github.com/zchee/go-xdgbasedir/home"
)
var (
defaultDataHome string
defaultConfigHome string
defaultDataDirs string
defaultConfigDirs string
defaultCacheHome string
defaultRuntimeDir string
)
func initDir() {
initOnce.Do(func() {
switch Mode {
case Unix:
defaultDataHome = filepath.Join(home.Dir(), ".local", "share")
defaultConfigHome = filepath.Join(home.Dir(), ".config")
defaultDataDirs = filepath.Join("/usr", "local", "share") + string(filepath.ListSeparator) + filepath.Join("/usr", "share")
defaultConfigDirs = filepath.Join("/etc", "xdg")
defaultCacheHome = filepath.Join(home.Dir(), ".cache")
defaultRuntimeDir = filepath.Join("/run", "user", strconv.Itoa(os.Getuid()))
case Native:
// ref: https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html
defaultDataHome = filepath.Join(home.Dir(), "Library", "Application Support")
defaultConfigHome = filepath.Join(home.Dir(), "Library", "Preferences")
defaultDataDirs = defaultDataHome
defaultConfigDirs = defaultConfigHome
defaultCacheHome = filepath.Join(home.Dir(), "Library", "Caches")
defaultRuntimeDir = defaultDataHome
}
})
}
func dataHome() string {
initDir()
return defaultDataHome
}
func configHome() string {
initDir()
return defaultConfigHome
}
func dataDirs() string {
initDir()
return defaultDataDirs
}
func configDirs() string {
initDir()
return defaultConfigDirs
}
func cacheHome() string {
initDir()
return defaultCacheHome
}
func runtimeDir() string {
initDir()
return defaultRuntimeDir
}