Skip to content

Commit

Permalink
Merge pull request #43 from imeoer/fix-converter-unpack
Browse files Browse the repository at this point in the history
converter: fix incomplete unpack
  • Loading branch information
imeoer committed Apr 21, 2022
2 parents 46d8445 + c10eff8 commit 6112f67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/converter/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,25 @@ func Convert(ctx context.Context, dest io.Writer, opt ConvertOption) (io.WriteCl

pr, pw := io.Pipe()

unpackDone := make(chan bool, 1)
go func() {
if err := unpackOciTar(ctx, sourceDir, pr); err != nil {
pr.CloseWithError(errors.Wrapf(err, "unpack to %s", sourceDir))
return
}
unpackDone <- true
}()

wc := newWriteCloser(pw, func() error {
defer func() {
os.RemoveAll(workDir)
}()

// Because PipeWriter#Close is called does not mean that the PipeReader
// has finished reading all the data, and unpack may not be complete yet,
// so we need to wait for that here.
<-unpackDone

bootstrapPath := filepath.Join(workDir, "bootstrap")
blobPath := filepath.Join(workDir, "blob")

Expand Down
9 changes: 6 additions & 3 deletions pkg/converter/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ func (c *writeCloser) Close() error {
if c.closed {
return nil
}
if err := c.action(); err != nil {
return err
}

if err := c.WriteCloser.Close(); err != nil {
return err
}
c.closed = true

if err := c.action(); err != nil {
return err
}

return nil
}

Expand Down

0 comments on commit 6112f67

Please sign in to comment.