MCPcopy Index your code
hub / github.com/devspace-sh/devspace / Execute

Method Execute

helper/server/upstream.go:293–321  ·  view source on GitHub ↗
(ctx context.Context, cmd *remote.Command)

Source from the content-addressed store, hash-verified

291}
292
293func (u *Upstream) Execute(ctx context.Context, cmd *remote.Command) (*remote.Empty, error) {
294 if cmd.Once {
295 hashString := cmd.Cmd
296 for _, arg := range cmd.Args {
297 hashString += arg
298 }
299
300 hashed := hash.String(hashString)
301 fileName := "/tmp/devspace-" + hashed
302 _, err := os.Stat(fileName)
303 if os.IsNotExist(err) {
304 err := os.WriteFile(fileName, []byte("1"), 0666)
305 if err != nil {
306 return nil, errors.Wrap(err, "writing hash file")
307 }
308 } else if err != nil {
309 return nil, errors.Wrap(err, "stat hash file")
310 } else {
311 return &remote.Empty{}, nil
312 }
313 }
314
315 out, err := exec.Command(cmd.Cmd, cmd.Args...).CombinedOutput()
316 if err != nil {
317 return nil, errors.Errorf("Error executing command '%s %s': %s => %v", cmd.Cmd, strings.Join(cmd.Args, " "), string(out), err)
318 }
319
320 return &remote.Empty{}, nil
321}

Callers

nothing calls this directly

Calls 2

StringFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected