Merge pull request #2379 from dmcgowan/fix-direct-io-terminal-setting

Fix creation of DirectIO overwriting fifo config
This commit is contained in:
Phil Estes 2018-06-02 12:25:14 +03:00 committed by GitHub
commit 84bebdd91d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 32 deletions

View File

@ -141,18 +141,8 @@ func openFifos(ctx context.Context, fifos *FIFOSet) (pipes, error) {
// NewDirectIO returns an IO implementation that exposes the IO streams as io.ReadCloser // NewDirectIO returns an IO implementation that exposes the IO streams as io.ReadCloser
// and io.WriteCloser. // and io.WriteCloser.
func NewDirectIO(ctx context.Context, fifos *FIFOSet) (*DirectIO, error) { func NewDirectIO(ctx context.Context, fifos *FIFOSet) (*DirectIO, error) {
return newDirectIO(ctx, fifos, false)
}
// NewDirectIOWithTerminal returns an IO implementation that exposes the streams with terminal enabled
func NewDirectIOWithTerminal(ctx context.Context, fifos *FIFOSet) (*DirectIO, error) {
return newDirectIO(ctx, fifos, true)
}
func newDirectIO(ctx context.Context, fifos *FIFOSet, terminal bool) (*DirectIO, error) {
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
pipes, err := openFifos(ctx, fifos) pipes, err := openFifos(ctx, fifos)
fifos.Config.Terminal = terminal
return &DirectIO{ return &DirectIO{
pipes: pipes, pipes: pipes,
cio: cio{ cio: cio{

View File

@ -60,7 +60,7 @@ func TestCheckpointRestorePTY(t *testing.T) {
} }
defer container.Delete(ctx, WithSnapshotCleanup) defer container.Delete(ctx, WithSnapshotCleanup)
direct, err := newDirectIOWithTerminal(ctx) direct, err := newDirectIO(ctx, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -92,7 +92,7 @@ func TestCheckpointRestorePTY(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
direct.Delete() direct.Delete()
direct, err = newDirectIOWithTerminal(ctx) direct, err = newDirectIO(ctx, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -281,7 +281,7 @@ func TestContainerPTY(t *testing.T) {
} }
defer container.Delete(ctx, WithSnapshotCleanup) defer container.Delete(ctx, WithSnapshotCleanup)
direct, err := newDirectIOWithTerminal(ctx) direct, err := newDirectIO(ctx, true)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -360,7 +360,7 @@ func TestContainerAttach(t *testing.T) {
expected := "hello" + newLine expected := "hello" + newLine
direct, err := newDirectIOStandard(ctx) direct, err := newDirectIO(ctx, false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -429,24 +429,12 @@ func TestContainerAttach(t *testing.T) {
} }
} }
func newDirectIOStandard(ctx context.Context) (*directIO, error) {
return newDirectIO(ctx, false)
}
func newDirectIOWithTerminal(ctx context.Context) (*directIO, error) {
return newDirectIO(ctx, true)
}
func newDirectIO(ctx context.Context, terminal bool) (*directIO, error) { func newDirectIO(ctx context.Context, terminal bool) (*directIO, error) {
fifos, err := cio.NewFIFOSetInDir("", "", false) fifos, err := cio.NewFIFOSetInDir("", "", terminal)
if err != nil { if err != nil {
return nil, err return nil, err
} }
f := cio.NewDirectIO dio, err := cio.NewDirectIO(ctx, fifos)
if terminal {
f = cio.NewDirectIOWithTerminal
}
dio, err := f(ctx, fifos)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -508,7 +496,7 @@ func TestContainerUsername(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
direct, err := newDirectIOStandard(ctx) direct, err := newDirectIO(ctx, false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -583,7 +571,7 @@ func testContainerUser(t *testing.T, userstr, expectedOutput string) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
direct, err := newDirectIOStandard(ctx) direct, err := newDirectIO(ctx, false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -668,7 +656,7 @@ func TestContainerAttachProcess(t *testing.T) {
expected := "hello" + newLine expected := "hello" + newLine
// creating IO early for easy resource cleanup // creating IO early for easy resource cleanup
direct, err := newDirectIOStandard(ctx) direct, err := newDirectIO(ctx, false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -775,7 +763,7 @@ func TestContainerUserID(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
direct, err := newDirectIOStandard(ctx) direct, err := newDirectIO(ctx, false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }