Skip to content

Commit

Permalink
docs: modify comments
Browse files Browse the repository at this point in the history
Signed-off-by: Zoey Li <zoeyli@microsoft.com>
  • Loading branch information
lizMSFT committed Aug 8, 2022
1 parent e2af366 commit 88483e5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,17 @@ func selectPlatform(ctx context.Context, src content.Storage, root ocispec.Descr
}
}

// WithTargetPlatform adds the check on the platform attributes.
func (o *CopyOptions) WithTargetPlatform(p *ocispec.Platform) {
mapRoot := o.MapRoot
o.MapRoot = func(ctx context.Context, src content.Storage, root ocispec.Descriptor) (desc ocispec.Descriptor, err error) {
// WithTargetPlatform configures opts.MapRoot to select the manifest whose
// platform matches the given platform. When MapRoot is provided, the platform
// selection will be applied on the mapped root node.
// - If the root node is a manifest, it will remain the same if platform
// matches, otherwise ErrNotFound will be returned.
// - If the root node is a manifest list, it will be mapped to the first
// matching manifest if exists, otherwise ErrNotFound will be returned.
// - Otherwise ErrUnsupported will be returned.
func (opts *CopyOptions) WithTargetPlatform(p *ocispec.Platform) {
mapRoot := opts.MapRoot
opts.MapRoot = func(ctx context.Context, src content.Storage, root ocispec.Descriptor) (desc ocispec.Descriptor, err error) {
if mapRoot != nil {
if root, err = mapRoot(ctx, src, root); err != nil {
return ocispec.Descriptor{}, err
Expand Down

0 comments on commit 88483e5

Please sign in to comment.