-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (60 loc) · 2.01 KB
/
main.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 main
import (
"argparser"
"config"
"exec"
"fmt"
"path/filepath"
"strings"
//"manifest"
"cache"
"utils"
"whash"
)
func main() {
var ConfigValues config.Config
var CommandtoExec []string
ConfigValues, CommandtoExec = argparser.ArgParse()
ConfigValues.ToolIdx = config.ToolMatcher(ConfigValues, CommandtoExec)
if ConfigValues.Mode == "learn" {
ConfigValues.CacheBaseDir = filepath.Join(ConfigValues.BaseDir, "LearningCache")
}
cmdexeced := false
infiles := []string{}
outfiles := []string{}
symlinks := [][2]string{}
logfile := ""
manifestFile := ""
env := utils.GetEnvironMap()
_, cmdhash, _ := whash.CommandHash(ConfigValues, env, CommandtoExec)
if strings.HasPrefix(ConfigValues.Mode, "read") || ConfigValues.Mode == "verify" {
manifestFile, _ = cache.FindManifest(ConfigValues, cmdhash)
if utils.Exists(manifestFile) && ConfigValues.Mode != "verify" {
fmt.Printf("Found manifest: %v, copying out from cache ...\n", manifestFile)
cache.CopyOut(ConfigValues, manifestFile)
fmt.Println("Done!")
}
}
if !utils.Exists(manifestFile) || ConfigValues.Mode == "verify" || ConfigValues.Mode == "learn" {
cmdexeced = true
_, logfile, infiles, outfiles, symlinks, _ = exec.RunCmd(ConfigValues, cmdhash, CommandtoExec)
}
if strings.Contains(ConfigValues.Mode, "write") && cmdexeced {
manifestFile, _ = cache.Create(ConfigValues, logfile, infiles, outfiles, symlinks, manifestFile)
fmt.Printf("\nCreated manifest: %v, copied output to cache\n", manifestFile)
}
if ConfigValues.Mode == "verify" && cmdexeced {
if utils.Exists(manifestFile) {
fmt.Println("Verifying ...")
if cache.Verify(ConfigValues, manifestFile) {
fmt.Println("All Matched.")
}
} else {
fmt.Printf("%v is not found and can't verify\n", manifestFile)
}
}
if ConfigValues.Mode == "learn" && cmdexeced {
fmt.Println("Learn Mode, executing the command second time, collect learning data ...")
_, logfile, infiles, outfiles, symlinks, _ = exec.RunCmd(ConfigValues, cmdhash, CommandtoExec)
}
}