Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func (e *Extractor) Gz(ctx context.Context, body io.Reader, location string, ren
// Tar extracts a .tar archived stream of data in the specified location.
// It accepts a rename function to handle the names of the files (see the example)
func (e *Extractor) Tar(ctx context.Context, body io.Reader, location string, rename Renamer) error {
files := []file{}
links := []link{}
symlinks := []link{}

Expand Down Expand Up @@ -141,11 +140,9 @@ func (e *Extractor) Tar(ctx context.Context, body io.Reader, location string, re
return errors.Annotatef(err, "Create directory %s", path)
}
case tar.TypeReg, tar.TypeRegA:
var data bytes.Buffer
if _, err := copyCancel(ctx, &data, tr); err != nil {
return errors.Annotatef(err, "Read contents of file %s", path)
if err := e.copy(ctx, path, info.Mode(), tr); err != nil {
return errors.Annotatef(err, "Create file %s", path)
}
files = append(files, file{Path: path, Mode: info.Mode(), Data: data})
case tar.TypeLink:
name := header.Linkname
if rename != nil {
Expand All @@ -159,13 +156,7 @@ func (e *Extractor) Tar(ctx context.Context, body io.Reader, location string, re
}
}

// Now we make another pass creating the files and links
for i := range files {
if err := e.copy(ctx, files[i].Path, files[i].Mode, &files[i].Data); err != nil {
return errors.Annotatef(err, "Create file %s", files[i].Path)
}
}

// Now we make another pass creating the links
for i := range links {
select {
case <-ctx.Done():
Expand Down