(tree *[]functions.FunctionT, procs *[]Process)
| 90 | } |
| 91 | |
| 92 | func (pc *previewCacheT) compile(tree *[]functions.FunctionT, procs *[]Process) error { |
| 93 | pc.mutex.Lock() |
| 94 | defer pc.mutex.Unlock() |
| 95 | |
| 96 | if pc.err != nil { |
| 97 | return pc.err |
| 98 | } |
| 99 | |
| 100 | s := make([]string, len(*tree)) |
| 101 | for i := range s { |
| 102 | s[i] = string((*tree)[i].Raw) |
| 103 | } |
| 104 | |
| 105 | offset, err := pc.compare(s) |
| 106 | if err != nil { |
| 107 | pc.err = err |
| 108 | return err |
| 109 | } |
| 110 | |
| 111 | if len(pc.raw) > 0 { |
| 112 | |
| 113 | safe := parser.GetSafeCmds() |
| 114 | for i := offset + 1; i < len(*tree)-1; i++ { |
| 115 | cmd := string((*tree)[i].CommandName()) |
| 116 | check: |
| 117 | switch { |
| 118 | case cmd == ExpressionFunctionName: |
| 119 | continue |
| 120 | case cmd == "exec" && !strings.HasPrefix(s[i], cmd): |
| 121 | if len((*tree)[i].Parameters) > 0 { |
| 122 | cmd = string((*tree)[i].Parameters[0]) |
| 123 | goto check |
| 124 | } |
| 125 | case !strings.HasPrefix(s[i], cmd): |
| 126 | return fmt.Errorf("a command executable has changed name: %s", errPressF9) |
| 127 | case !lists.Match(safe, cmd): |
| 128 | return fmt.Errorf("a command line change has been made prior to potentially unsafe commands: %s", errPressF9) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | } |
| 133 | |
| 134 | pc.grow(s) |
| 135 | |
| 136 | for i := 0; i < len(*procs)-1; i++ { |
| 137 | (*procs)[i].cache = new(cacheT) |
| 138 | (*procs)[i].cache.b = &pc.cache[i] |
| 139 | (*procs)[i].cache.dt = &pc.dt[i] |
| 140 | (*procs)[i].Stdout, (*procs)[i].cache.tee.stdout = streams.NewTee((*procs)[i].Stdout) |
| 141 | (*procs)[i].Stderr, (*procs)[i].cache.tee.stderr = streams.NewTee((*procs)[i].Stderr) |
| 142 | |
| 143 | if i <= offset { |
| 144 | (*procs)[i].cache.use = true |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | return nil |
| 149 | } |
no test coverage detected