1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #8321 from erikh/ui_save_output

docker save: Do not save to a terminal.
This commit is contained in:
Tibor Vass 2014-10-24 19:37:14 -04:00
commit 350e1b783d
2 changed files with 35 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
@ -2411,7 +2412,10 @@ func (cli *DockerCli) CmdSave(args ...string) error {
if err != nil {
return err
}
} else if cli.isTerminalOut {
return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.")
}
if len(cmd.Args()) == 1 {
image := cmd.Arg(0)
if err := cli.stream("GET", "/images/"+image+"/get", nil, output, nil); err != nil {

View file

@ -1,6 +1,7 @@
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
@ -8,6 +9,8 @@ import (
"path/filepath"
"reflect"
"testing"
"github.com/docker/docker/vendor/src/github.com/kr/pty"
)
// save a repo and try to load it using stdout
@ -70,6 +73,34 @@ func TestSaveAndLoadRepoStdout(t *testing.T) {
logDone("save - save a repo using stdout")
logDone("load - load a repo using stdout")
pty, tty, err := pty.Open()
if err != nil {
t.Fatalf("Could not open pty: %v", err)
}
cmd := exec.Command(dockerBinary, "save", repoName)
cmd.Stdin = tty
cmd.Stdout = tty
cmd.Stderr = tty
if err := cmd.Start(); err != nil {
t.Fatalf("start err: %v", err)
}
if err := cmd.Wait(); err == nil {
t.Fatal("did not break writing to a TTY")
}
buf := make([]byte, 1024)
n, err := pty.Read(buf)
if err != nil {
t.Fatal("could not read tty output")
}
if !bytes.Contains(buf[:n], []byte("Cowardly refusing")) {
t.Fatal("help output is not being yielded", out)
}
logDone("save - do not save to a tty")
}
func TestSaveSingleTag(t *testing.T) {