(ctx context.Context, client kubectl.Client, pod *k8sv1.Pod, container string, localPath string, containerPath string, log logpkg.Logger)
| 57 | } |
| 58 | |
| 59 | func download(ctx context.Context, client kubectl.Client, pod *k8sv1.Pod, container string, localPath string, containerPath string, log logpkg.Logger) error { |
| 60 | prefix := getPrefix(containerPath) |
| 61 | prefix = path.Clean(prefix) |
| 62 | // remove extraneous path shortcuts - these could occur if a path contained extra "../" |
| 63 | // and attempted to navigate beyond "/" in a remote filesystem |
| 64 | prefix = stripPathShortcuts(prefix) |
| 65 | |
| 66 | // do the actual copy |
| 67 | reader, writer := io.Pipe() |
| 68 | errorChan := make(chan error) |
| 69 | go func() { |
| 70 | defer writer.Close() |
| 71 | errorChan <- downloadFromPod(ctx, client, pod, container, containerPath, writer) |
| 72 | }() |
| 73 | go func() { |
| 74 | defer reader.Close() |
| 75 | errorChan <- untarAll(reader, localPath, prefix, log) |
| 76 | }() |
| 77 | err := <-errorChan |
| 78 | // wait for the second goroutine to finish |
| 79 | <-errorChan |
| 80 | return err |
| 81 | } |
| 82 | |
| 83 | func downloadFromPod(ctx context.Context, client kubectl.Client, pod *k8sv1.Pod, container, containerPath string, writer io.Writer) error { |
| 84 | stderr := &bytes.Buffer{} |
no test coverage detected