forked from openpitrix/libconfd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
executable file
·71 lines (61 loc) · 1.14 KB
/
util.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
// Copyright confd. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE-confd file.
package libconfd
import (
"os"
"runtime"
"strings"
)
// fileInfo describes a configuration file and is returned by readFileStat.
type fileInfo struct {
Uid uint32
Gid uint32
Mode os.FileMode
Md5 string
}
func dirExists(path string) bool {
fi, err := os.Stat(path)
if err != nil {
return false
}
if !fi.IsDir() {
return false
}
return true
}
func fileExists(path string) bool {
if _, err := os.Stat(path); err == nil {
return true
}
return false
}
func fileNotExists(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return true
}
return false
}
func getFuncName(skips ...int) string {
var skip = 1
if len(skips) > 0 {
skip = skips[0]
}
pc, _, _, ok := runtime.Caller(skip)
if !ok {
return ""
}
name := runtime.FuncForPC(pc).Name()
if idx := strings.LastIndex(name, "/"); idx >= 0 {
name = name[idx+1:]
}
return name
}
func strInStrList(s string, ss []string) bool {
for _, t := range ss {
if s == t {
return true
}
}
return false
}