forked from shibukawa/git4go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysdir.go
38 lines (35 loc) · 744 Bytes
/
sysdir.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
package git4go
import (
"errors"
"fmt"
"os"
"path/filepath"
)
var dirListCache map[string][]string = make(map[string][]string)
func findInDirList(name string, label string) (string, error) {
dirs, ok := dirListCache[label]
if !ok {
switch label {
case "system":
dirs = guessSystemFile()
case "global":
dirs = guessGlobalFile()
case "global/xdg":
dirs = guessXDGFile()
case "template":
dirs = guessTemplateFile()
}
dirListCache[label] = dirs
}
for _, dir := range dirs {
path := dir
if name != "" {
path = filepath.Join(path, name)
}
_, err := os.Stat(path)
if !os.IsNotExist(err) {
return path, nil
}
}
return "", errors.New(fmt.Sprintf("The %s file '%s' doesn't exist", label, name))
}