MCPcopy
hub / github.com/slimtoolkit/slim / EnsureLocalBinary

Function EnsureLocalBinary

pkg/app/master/inspectors/sensor/sensor.go:22–66  ·  view source on GitHub ↗
(xc *app.ExecutionContext, logger *log.Entry, statePath string, printState bool)

Source from the content-addressed store, hash-verified

20)
21
22func EnsureLocalBinary(xc *app.ExecutionContext, logger *log.Entry, statePath string, printState bool) string {
23 sensorPath := filepath.Join(fsutil.ExeDir(), LocalBinFile)
24
25 if runtime.GOOS == "darwin" {
26 stateSensorPath := filepath.Join(statePath, LocalBinFile)
27 if fsutil.Exists(stateSensorPath) {
28 sensorPath = stateSensorPath
29 }
30 }
31
32 if !fsutil.Exists(sensorPath) {
33 if printState {
34 xc.Out.Info("sensor.error",
35 ovars{
36 "message": "sensor binary not found",
37 "location": sensorPath,
38 })
39
40 xc.Out.State("exited",
41 ovars{
42 "exit.code": -125,
43 "component": "container.inspector",
44 "version": v.Current(),
45 })
46 }
47
48 xc.Exit(-125)
49 }
50
51 if finfo, err := os.Lstat(sensorPath); err == nil {
52 logger.Debugf("sensor.EnsureLocalBinary: sensor (%s) perms => %#o", sensorPath, finfo.Mode().Perm())
53 if finfo.Mode().Perm()&fsutil.FilePermUserExe == 0 {
54 logger.Debugf("sensor.EnsureLocalBinary: sensor (%s) missing execute permission", sensorPath)
55 updatedMode := finfo.Mode() | fsutil.FilePermUserExe | fsutil.FilePermGroupExe | fsutil.FilePermOtherExe
56 if err = os.Chmod(sensorPath, updatedMode); err != nil {
57 logger.Errorf("sensor.EnsureLocalBinary: error updating sensor (%s) perms (%#o -> %#o) => %v",
58 sensorPath, finfo.Mode().Perm(), updatedMode.Perm(), err)
59 }
60 }
61 } else {
62 logger.Errorf("sensor.EnsureLocalBinary: error getting sensor (%s) info => %#v", sensorPath, err)
63 }
64
65 return sensorPath
66}

Callers 2

RunContainerMethod · 0.92
RunPodMethod · 0.92

Calls 6

ExeDirFunction · 0.92
ExistsFunction · 0.92
ExitMethod · 0.80
ModeMethod · 0.80
StateMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected