|
@@ -3,7 +3,6 @@ package client
|
|
|
import (
|
|
|
"errors"
|
|
|
"io"
|
|
|
- "os"
|
|
|
|
|
|
Cli "github.com/docker/docker/cli"
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
@@ -21,19 +20,9 @@ func (cli *DockerCli) CmdSave(args ...string) error {
|
|
|
|
|
|
cmd.ParseFlags(args, true)
|
|
|
|
|
|
- var (
|
|
|
- output = cli.out
|
|
|
- err error
|
|
|
- )
|
|
|
-
|
|
|
if *outfile == "" && cli.isTerminalOut {
|
|
|
return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.")
|
|
|
}
|
|
|
- if *outfile != "" {
|
|
|
- if output, err = os.Create(*outfile); err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
responseBody, err := cli.client.ImageSave(cmd.Args())
|
|
|
if err != nil {
|
|
@@ -41,6 +30,11 @@ func (cli *DockerCli) CmdSave(args ...string) error {
|
|
|
}
|
|
|
defer responseBody.Close()
|
|
|
|
|
|
- _, err = io.Copy(output, responseBody)
|
|
|
- return err
|
|
|
+ if *outfile == "" {
|
|
|
+ _, err := io.Copy(cli.out, responseBody)
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ return copyToFile(*outfile, responseBody)
|
|
|
+
|
|
|
}
|