Skip to content

Commit

Permalink
ensure wrappers support seeking to continue partial downloads
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Jul 15, 2021
1 parent 311ff35 commit c1f2f7a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions util/contentutil/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ func (r *rc) Read(b []byte) (int, error) {
return n, err
}

func (r *rc) Seek(offset int64, whence int) (int64, error) {
switch whence {
case io.SeekStart:
r.offset = int(offset)
case io.SeekCurrent:
r.offset += int(offset)
case io.SeekEnd:
r.offset = int(r.Size()) - int(offset)
}
return int64(r.offset), nil
}

func CopyChain(ctx context.Context, ingester content.Ingester, provider content.Provider, desc ocispec.Descriptor) error {
var m sync.Mutex
manifestStack := []ocispec.Descriptor{}
Expand Down
10 changes: 10 additions & 0 deletions util/resolver/limited/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (f *fetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCl
release()
return nil, err
}

rcw := &readCloser{ReadCloser: rc}
closer := func() {
if !rcw.closed {
Expand All @@ -161,9 +162,18 @@ func (f *fetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCl
rc.close()
})

if s, ok := rc.(io.Seeker); ok {
return &readCloserSeeker{rcw, s}, nil
}

return rcw, nil
}

type readCloserSeeker struct {
*readCloser
io.Seeker
}

type readCloser struct {
io.ReadCloser
once sync.Once
Expand Down

0 comments on commit c1f2f7a

Please sign in to comment.