Skip to content

Commit

Permalink
Review feedback: make StartExec use StartExecNonBlocking etc
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwilkie committed Dec 15, 2015
1 parent 3392218 commit 4dd2c21
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 38 deletions.
12 changes: 1 addition & 11 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1036,17 +1036,7 @@ type AttachToContainerOptions struct {
//
// See https://goo.gl/NKpkFk for more details.
func (c *Client) AttachToContainer(opts AttachToContainerOptions) error {
if opts.Container == "" {
return &NoSuchContainer{ID: opts.Container}
}
path := "/containers/" + opts.Container + "/attach?" + queryString(opts)
cw, err := c.hijack("POST", path, hijackOptions{
success: opts.Success,
setRawTerminal: opts.RawTerminal,
in: opts.InputStream,
stdout: opts.OutputStream,
stderr: opts.ErrorStream,
})
cw, err := c.AttachToContainerNonBlocking(opts)
if err != nil {
return err
}
Expand Down
32 changes: 5 additions & 27 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,36 +83,14 @@ type StartExecOptions struct {
//
// See https://goo.gl/iQCnto for more details
func (c *Client) StartExec(id string, opts StartExecOptions) error {
if id == "" {
return &NoSuchExec{ID: id}
}

path := fmt.Sprintf("/exec/%s/start", id)

if opts.Detach {
resp, err := c.do("POST", path, doOptions{data: opts})
if err != nil {
if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
return &NoSuchExec{ID: id}
}
return err
}
defer resp.Body.Close()
return nil
}

cw, err := c.hijack("POST", path, hijackOptions{
success: opts.Success,
setRawTerminal: opts.RawTerminal,
in: opts.InputStream,
stdout: opts.OutputStream,
stderr: opts.ErrorStream,
data: opts,
})
cw, err := c.StartExecNonBlocking(id, opts)
if err != nil {
return err
}
return cw.Wait()
if cw != nil {
return cw.Wait()
}
return nil
}

// StartExecNonBlocking starts a previously set up exec instance id. If opts.Detach is
Expand Down

0 comments on commit 4dd2c21

Please sign in to comment.