MCPcopy Index your code
hub / github.com/coder/coder / versionFromBinaryPath

Function versionFromBinaryPath

provisioner/terraform/executor.go:183–207  ·  view source on GitHub ↗
(ctx context.Context, binaryPath string)

Source from the content-addressed store, hash-verified

181}
182
183func versionFromBinaryPath(ctx context.Context, binaryPath string) (*version.Version, error) {
184 if ctx.Err() != nil {
185 return nil, ctx.Err()
186 }
187
188 // #nosec
189 cmd := exec.CommandContext(ctx, binaryPath, "version", "-json")
190 out, err := cmd.Output()
191 if err != nil {
192 select {
193 // `exec` library throws a `signal: killed`` error instead of the canceled context.
194 // Since we know the cause for the killed signal, we are throwing the relevant error here.
195 case <-ctx.Done():
196 return nil, ctx.Err()
197 default:
198 return nil, err
199 }
200 }
201 vj := tfjson.VersionOutput{}
202 err = json.Unmarshal(out, &vj)
203 if err != nil {
204 return nil, err
205 }
206 return version.NewVersion(vj.Version)
207}
208
209type textFileBusyError struct {
210 exitErr *exec.ExitError

Callers 3

versionMethod · 0.85
InstallFunction · 0.85
systemBinaryFunction · 0.85

Calls 5

ErrMethod · 0.80
CommandContextMethod · 0.65
OutputMethod · 0.65
DoneMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected