(dockerCli command.Cli, reader io.Reader, dest string)
| 33 | } |
| 34 | |
| 35 | func writeTo(dockerCli command.Cli, reader io.Reader, dest string) error { |
| 36 | var writer io.Writer |
| 37 | var printDest bool |
| 38 | if dest == "-" { |
| 39 | if dockerCli.Out().IsTerminal() { |
| 40 | return errors.New("cowardly refusing to export to a terminal, specify a file path") |
| 41 | } |
| 42 | writer = dockerCli.Out() |
| 43 | } else { |
| 44 | f, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o600) |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | defer f.Close() |
| 49 | writer = f |
| 50 | printDest = true |
| 51 | } |
| 52 | if _, err := io.Copy(writer, reader); err != nil { |
| 53 | return err |
| 54 | } |
| 55 | if printDest { |
| 56 | fmt.Fprintf(dockerCli.Err(), "Written file %q\n", dest) |
| 57 | } |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | // runExport exports a Docker context. |
| 62 | func runExport(dockerCLI command.Cli, contextName string, dest string) error { |
no test coverage detected
searching dependent graphs…