diff --git a/cmd/oras/root/manifest/index/create.go b/cmd/oras/root/manifest/index/create.go index 12b51e95d..c8040559f 100644 --- a/cmd/oras/root/manifest/index/create.go +++ b/cmd/oras/root/manifest/index/create.go @@ -153,12 +153,8 @@ func fetchSourceManifests(ctx context.Context, target oras.ReadOnlyTarget, opts return nil, fmt.Errorf("%s is not a manifest", source) } opts.Println(status.IndexPromptFetched, source) - desc = descriptor.Plain(desc) - if descriptor.IsImageManifest(desc) { - desc.Platform, err = getPlatform(ctx, target, content) - if err != nil { - return nil, err - } + if desc, err = enrichDescriptor(ctx, target, desc, content); err != nil { + return nil, err } resolved = append(resolved, desc) } @@ -209,3 +205,15 @@ func pushIndex(ctx context.Context, target oras.Target, desc ocispec.Descriptor, } return printer.Println("Digest:", desc.Digest) } + +func enrichDescriptor(ctx context.Context, target oras.ReadOnlyTarget, desc ocispec.Descriptor, manifestBytes []byte) (ocispec.Descriptor, error) { + desc = descriptor.Plain(desc) + if descriptor.IsImageManifest(desc) { + var err error + desc.Platform, err = getPlatform(ctx, target, manifestBytes) + if err != nil { + return ocispec.Descriptor{}, err + } + } + return desc, nil +} diff --git a/cmd/oras/root/manifest/index/update.go b/cmd/oras/root/manifest/index/update.go index d8a43b07c..7bff8a259 100644 --- a/cmd/oras/root/manifest/index/update.go +++ b/cmd/oras/root/manifest/index/update.go @@ -181,11 +181,8 @@ func addManifests(ctx context.Context, manifests []ocispec.Descriptor, target or return nil, fmt.Errorf("%s is not a manifest", manifestRef) } printUpdateStatus(status.IndexPromptFetched, manifestRef, string(desc.Digest), opts.Printer) - if descriptor.IsImageManifest(desc) { - desc.Platform, err = getPlatform(ctx, target, content) - if err != nil { - return nil, err - } + if desc, err = enrichDescriptor(ctx, target, desc, content); err != nil { + return nil, err } manifests = append(manifests, desc) printUpdateStatus(status.IndexPromptAdded, manifestRef, string(desc.Digest), opts.Printer)