-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathutils.go
65 lines (56 loc) · 989 Bytes
/
utils.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
package utils
import (
"bufio"
"fmt"
"os"
"os/exec"
)
var (
PathSeparator = fmt.Sprintf("%c", os.PathSeparator)
)
func CacheDir() string {
cacheDir, err := os.UserCacheDir()
if err != nil {
cacheDir = os.TempDir()
}
return cacheDir
}
func StringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
func IsCommandAvailable(name string) bool {
if _, err := exec.LookPath(name); err != nil {
return false
}
return true
}
func IsGzip(f *bufio.Reader) bool {
buf, err := f.Peek(3)
if err != nil {
return false
}
return buf[0] == 0x1F && buf[1] == 0x8B && buf[2] == 0x8
}
func Keys(m map[string]struct{}) []string {
var keys []string
for k := range m {
keys = append(keys, k)
}
return keys
}
func IsExecutable(fileInfo os.FileInfo) bool {
mode := fileInfo.Mode()
if !mode.IsRegular() {
return false
}
// Check executable file
if mode.Perm()&0111 != 0 {
return true
}
return false
}