Skip to content

Commit

Permalink
fix: update --add should add plain descriptor (#1513)
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 authored Oct 14, 2024
1 parent 304a89f commit 1d60e22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
20 changes: 14 additions & 6 deletions cmd/oras/root/manifest/index/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
7 changes: 2 additions & 5 deletions cmd/oras/root/manifest/index/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1d60e22

Please sign in to comment.