/
job.go
95 lines (77 loc) · 1.82 KB
/
job.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
90
91
92
93
94
95
package golang
import (
"os"
"syscall"
"github.com/debricked/cli/internal/callgraph/cgexec"
conf "github.com/debricked/cli/internal/callgraph/config"
"github.com/debricked/cli/internal/callgraph/job"
"github.com/debricked/cli/internal/io"
ioFs "github.com/debricked/cli/internal/io"
)
const (
outputName = "debricked-call-graph.golang"
)
type Job struct {
job.BaseJob
mainFile string
config conf.IConfig
archive io.IArchive
ctx cgexec.IContext
fs ioFs.IFileSystem
}
func NewJob(dir string, mainFile string, writer ioFs.IFileWriter, archive io.IArchive, config conf.IConfig, ctx cgexec.IContext, fs ioFs.IFileSystem) *Job {
return &Job{
BaseJob: job.NewBaseJob(dir, []string{mainFile}),
mainFile: mainFile,
config: config,
archive: archive,
ctx: ctx,
fs: fs,
}
}
func (j *Job) Run() {
workingDirectory := j.GetDir()
callgraph := NewCallgraphBuilder(
workingDirectory,
j.mainFile,
outputName,
j.fs,
j.ctx,
)
j.SendStatus("generating call graph")
j.runCallGraph(&callgraph)
if j.Errors().HasError() {
return
}
}
func (j *Job) runCallGraph(callgraph ICallgraphBuilder) {
outputFullPath, err := callgraph.RunCallGraph()
if err != nil {
j.Errors().Critical(err)
return
}
outputFullPathZip := outputFullPath + ".zip"
j.SendStatus("zipping callgraph")
err = j.archive.ZipFile(outputFullPath, outputFullPathZip, outputName)
if err != nil {
j.Errors().Critical(err)
return
}
j.SendStatus("base64 encoding zipped callgraph")
err = j.archive.B64(outputFullPathZip, outputFullPath)
if err != nil {
j.Errors().Critical(err)
return
}
j.SendStatus("cleanup")
err = j.archive.Cleanup(outputFullPathZip)
if err != nil {
e, ok := err.(*os.PathError)
if ok && e.Err == syscall.ENOENT {
return
} else {
j.Errors().Critical(err)
return
}
}
}