Skip to content

Commit 534be84

Browse files
authored
Merge pull request #4529 from gongguan/creator
avoid unnecessary NewCreator calls
2 parents 68d9733 + 0dea724 commit 534be84

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

cmd/ctr/commands/tasks/tasks_unix.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,30 +72,29 @@ func NewTask(ctx gocontext.Context, client *containerd.Client, container contain
7272
stdinC := &stdinCloser{
7373
stdin: os.Stdin,
7474
}
75-
stdio := cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
7675
if checkpoint != "" {
7776
im, err := client.GetImage(ctx, checkpoint)
7877
if err != nil {
7978
return nil, err
8079
}
8180
opts = append(opts, containerd.WithTaskCheckpoint(im))
8281
}
83-
ioCreator := stdio
82+
var ioCreator cio.Creator
8483
if con != nil {
85-
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
86-
}
87-
if nullIO {
88-
if con != nil {
84+
if nullIO {
8985
return nil, errors.New("tty and null-io cannot be used together")
9086
}
87+
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(con, con, nil), cio.WithTerminal}, ioOpts...)...)
88+
} else if nullIO {
9189
ioCreator = cio.NullIO
92-
}
93-
if logURI != "" {
90+
} else if logURI != "" {
9491
u, err := url.Parse(logURI)
9592
if err != nil {
9693
return nil, err
9794
}
9895
ioCreator = cio.LogURI(u)
96+
} else {
97+
ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStreams(stdinC, os.Stdout, os.Stderr)}, ioOpts...)...)
9998
}
10099
t, err := container.NewTask(ctx, ioCreator, opts...)
101100
if err != nil {

0 commit comments

Comments
 (0)