forked from gravityblast/fresh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
89 lines (71 loc) · 1.59 KB
/
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package runner
import (
"os"
"path/filepath"
"strings"
)
func initFolders() {
runnerLog("InitFolders")
path := tmpPath()
runnerLog("mkdir %s", path)
err := os.Mkdir(path, 0755)
if err != nil {
runnerLog(err.Error())
}
}
func isTmpDir(path string) bool {
absolutePath, _ := filepath.Abs(path)
absoluteTmpPath, _ := filepath.Abs(tmpPath())
return absolutePath == absoluteTmpPath
}
func isIgnoredFolder(path string) bool {
paths := strings.Split(path, "/")
if len(paths) <= 0 {
return false
}
for _, e := range strings.Split(settings["ignored"], ",") {
if strings.TrimSpace(e) == paths[0] {
return true
}
}
return false
}
func isWatchedFile(path string) bool {
absolutePath, _ := filepath.Abs(path)
absoluteTmpPath, _ := filepath.Abs(tmpPath())
if strings.HasPrefix(absolutePath, absoluteTmpPath) {
return false
}
ext := filepath.Ext(path)
for _, e := range strings.Split(settings["valid_ext"], ",") {
if strings.TrimSpace(e) == ext {
return true
}
}
return false
}
func shouldRebuild(eventName string) bool {
for _, e := range strings.Split(settings["no_rebuild_ext"], ",") {
e = strings.TrimSpace(e)
fileName := strings.Replace(strings.Split(eventName, ":")[0], `"`, "", -1)
if strings.HasSuffix(fileName, e) {
return false
}
}
return true
}
func createBuildErrorsLog(message string) bool {
file, err := os.Create(buildErrorsFilePath())
if err != nil {
return false
}
_, err = file.WriteString(message)
if err != nil {
return false
}
return true
}
func removeBuildErrorsLog() error {
err := os.Remove(buildErrorsFilePath())
return err
}