Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce visibility of ProviderWrapper #45

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/oras/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func transferContent(ctx context.Context, desc ocispec.Descriptor, fetcher remot
handlers = append(handlers,
fetchHandler,
picker,
images.ChildrenHandler(&ProviderWrapper{Fetcher: store}),
newProviderHandler(store),
)
handlers = append(handlers, opts.callbackHandlers...)

Expand Down
17 changes: 11 additions & 6 deletions pkg/oras/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@ import (
"io"

"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/remotes"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

// ProviderWrapper wraps a remote.Fetcher to make a content.Provider, which is useful for things
type ProviderWrapper struct {
Fetcher remotes.Fetcher
func newProviderHandler(store remotes.Fetcher) images.HandlerFunc {
return images.ChildrenHandler(&providerWrapper{fetcher: store})
}

func (p *ProviderWrapper) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) {
if p.Fetcher == nil {
// providerWrapper wraps a remote.Fetcher and ReaderAt
type providerWrapper struct {
fetcher remotes.Fetcher
}

func (p *providerWrapper) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) {
if p.fetcher == nil {
return nil, errors.New("no Fetcher provided")
}
return &fetcherReaderAt{
ctx: ctx,
fetcher: p.Fetcher,
fetcher: p.fetcher,
desc: desc,
offset: 0,
}, nil
Expand Down