(cfg *config.Configuration, request *pipeRequest)
| 42 | } |
| 43 | |
| 44 | func pipeExtensions(cfg *config.Configuration, request *pipeRequest) (response pipeResponse, err error) { |
| 45 | var extcmds []*extCommand |
| 46 | defer func() { |
| 47 | // In the case of an early return before the end of this |
| 48 | // function (in response to an error, etc), kill all running |
| 49 | // processes. Errors are ignored since the function has already |
| 50 | // returned. |
| 51 | // |
| 52 | // In the happy path, the commands will have already been |
| 53 | // `Wait()`-ed upon and e.cmd.Process.Kill() will return an |
| 54 | // error, but we can ignore it. |
| 55 | for _, e := range extcmds { |
| 56 | if e.cmd.Process != nil { |
| 57 | e.cmd.Process.Kill() |
| 58 | } |
| 59 | } |
| 60 | }() |
| 61 | |
| 62 | for _, e := range request.extensions { |
| 63 | var pieces []string |
| 64 | switch request.action { |
| 65 | case "clean": |
| 66 | pieces = strings.Split(e.Clean, " ") |
| 67 | case "smudge": |
| 68 | pieces = strings.Split(e.Smudge, " ") |
| 69 | default: |
| 70 | err = errors.New(tr.Tr.Get("Invalid action: %s", request.action)) |
| 71 | return |
| 72 | } |
| 73 | name := strings.Trim(pieces[0], " ") |
| 74 | var args []string |
| 75 | for _, value := range pieces[1:] { |
| 76 | arg := strings.Replace(value, "%f", request.fileName, -1) |
| 77 | args = append(args, arg) |
| 78 | } |
| 79 | var cmd *subprocess.Cmd |
| 80 | cmd, err = subprocess.ExecCommand(name, args...) |
| 81 | if err != nil { |
| 82 | return |
| 83 | } |
| 84 | ec := &extCommand{cmd: cmd, result: &pipeExtResult{name: e.Name}} |
| 85 | extcmds = append(extcmds, ec) |
| 86 | } |
| 87 | |
| 88 | hasher := sha256.New() |
| 89 | pipeReader, pipeWriter := io.Pipe() |
| 90 | multiWriter := io.MultiWriter(hasher, pipeWriter) |
| 91 | |
| 92 | var input io.Reader |
| 93 | var output io.WriteCloser |
| 94 | input = pipeReader |
| 95 | extcmds[0].cmd.Stdin = input |
| 96 | if response.file, err = TempFile(cfg, ""); err != nil { |
| 97 | return |
| 98 | } |
| 99 | defer response.file.Close() |
| 100 | output = response.file |
| 101 |
no test coverage detected