(ops []PathMapping)
| 319 | } |
| 320 | |
| 321 | func tarArchive(ops []PathMapping) io.ReadCloser { |
| 322 | pr, pw := io.Pipe() |
| 323 | go func() { |
| 324 | ab := NewArchiveBuilder(pw) |
| 325 | err := ab.ArchivePathsIfExist(ops) |
| 326 | if err != nil { |
| 327 | _ = pw.CloseWithError(fmt.Errorf("adding files to tar: %w", err)) |
| 328 | } else { |
| 329 | // propagate errors from the TarWriter::Close() because it performs a final |
| 330 | // Flush() and any errors mean the tar is invalid |
| 331 | if err := ab.Close(); err != nil { |
| 332 | _ = pw.CloseWithError(fmt.Errorf("closing tar: %w", err)) |
| 333 | } else { |
| 334 | _ = pw.Close() |
| 335 | } |
| 336 | } |
| 337 | }() |
| 338 | return pr |
| 339 | } |
| 340 | |
| 341 | // Dedupe the entries with last-entry-wins semantics. |
| 342 | func dedupeEntries(entries []archiveEntry) []archiveEntry { |
no test coverage detected