Skip to content

Commit

Permalink
Merge pull request moby#5254 from tonistiigi/uploadprovider-closer
Browse files Browse the repository at this point in the history
uploadprovider: allow closing used sources
  • Loading branch information
AkihiroSuda authored Aug 17, 2024
2 parents 51c2a75 + 3294c68 commit d581877
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5311,7 +5311,7 @@ COPY foo /
defer c.Close()

up := uploadprovider.New()
url := up.Add(buf)
url := up.Add(io.NopCloser(buf))

_, err = f.Solve(sb.Context(), c, client.SolveOpt{
FrontendAttrs: map[string]string{
Expand Down Expand Up @@ -5356,7 +5356,7 @@ COPY foo bar
defer c.Close()

up := uploadprovider.New()
url := up.Add(buf)
url := up.Add(io.NopCloser(buf))

// repeat with changed default args should match the old cache
destDir := t.TempDir()
Expand Down
11 changes: 8 additions & 3 deletions session/upload/uploadprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
)

func New() *Uploader {
return &Uploader{m: map[string]io.Reader{}}
return &Uploader{m: map[string]io.ReadCloser{}}
}

type Uploader struct {
mu sync.Mutex
m map[string]io.Reader
m map[string]io.ReadCloser
}

func (hp *Uploader) Add(r io.Reader) string {
func (hp *Uploader) Add(r io.ReadCloser) string {
id := identity.NewID()
hp.m[id] = r
return "http://buildkit-session/" + id
Expand Down Expand Up @@ -51,6 +51,11 @@ func (hp *Uploader) Pull(stream upload.Upload_PullServer) error {
hp.mu.Unlock()

_, err := io.Copy(&writer{stream}, r)

if err1 := r.Close(); err == nil {
err = err1
}

return err
}

Expand Down

0 comments on commit d581877

Please sign in to comment.