Skip to content

Commit

Permalink
Merge pull request #4529 from gongguan/creator
Browse files Browse the repository at this point in the history
avoid unnecessary NewCreator calls
  • Loading branch information
estesp committed Sep 21, 2020
2 parents 68d9733 + 0dea724 commit 534be84
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions cmd/ctr/commands/tasks/tasks_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,29 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
stdinC := &stdinCloser{
stdin: os.Stdin,
}
stdio := cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
if checkpoint != "" {
im, err := client.GetImage(ctx, checkpoint)
if err != nil {
return nil, err
}
opts = append(opts, containerd.WithTaskCheckpoint(im))
}
ioCreator := stdio
var ioCreator cio.Creator
if con != nil {
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
}
if nullIO {
if con != nil {
if nullIO {
return nil, errors.New("tty and null-io cannot be used together")
}
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
} else if nullIO {
ioCreator = cio.NullIO
}
if logURI != "" {
} else if logURI != "" {
u, err := url.Parse(logURI)
if err != nil {
return nil, err
}
ioCreator = cio.LogURI(u)
} else {
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
}
t, err := container.NewTask(ctx, ioCreator, opts...)
if err != nil {
Expand Down

0 comments on commit 534be84

Please sign in to comment.