(ctx context.Context, dockerCLI command.Cli, opts exportOptions)
| 46 | } |
| 47 | |
| 48 | func runExport(ctx context.Context, dockerCLI command.Cli, opts exportOptions) error { |
| 49 | var output io.Writer |
| 50 | if opts.output == "" { |
| 51 | if dockerCLI.Out().IsTerminal() { |
| 52 | return errors.New("cowardly refusing to save to a terminal. Use the -o flag or redirect") |
| 53 | } |
| 54 | output = dockerCLI.Out() |
| 55 | } else { |
| 56 | writer, err := atomicwriter.New(opts.output, 0o600) |
| 57 | if err != nil { |
| 58 | return fmt.Errorf("failed to export container: %w", err) |
| 59 | } |
| 60 | defer writer.Close() |
| 61 | output = writer |
| 62 | } |
| 63 | |
| 64 | responseBody, err := dockerCLI.Client().ContainerExport(ctx, opts.container, client.ContainerExportOptions{}) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | defer responseBody.Close() |
| 69 | |
| 70 | _, err = io.Copy(output, responseBody) |
| 71 | return err |
| 72 | } |
no test coverage detected
searching dependent graphs…