Skip to content

Commit

Permalink
Merge branch 'refactor' of https://github.com/qweeah/oras into refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
qweeah committed Aug 15, 2022
2 parents 4525eea + 89c96ed commit 4349084
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/oras/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"oras.land/oras/cmd/oras/internal/errors"
"oras.land/oras/cmd/oras/internal/option"
"oras.land/oras/internal/cache"
"oras.land/oras/internal/docker"
)

type pullOptions struct {
Expand Down Expand Up @@ -102,15 +103,20 @@ func runPull(opts pullOptions) error {

// Copy Options
copyOptions := oras.DefaultCopyOptions
configPath, configMediaType := parseFileReference(opts.ManifestConfigRef, oras.MediaTypeUnknownConfig)
configPath, configMediaType := parseFileReference(opts.ManifestConfigRef, "")
copyOptions.FindSuccessors = func(ctx context.Context, fetcher content.Fetcher, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
successors, err := content.Successors(ctx, fetcher, desc)
if err != nil {
return nil, err
}
var ret []ocispec.Descriptor
for _, s := range successors {
if s.MediaType == configMediaType {
for i, s := range successors {
// Save the config when:
// 1) MediaType matches, or
// 2) MediaType not specified and current node is config.
// Note: For a manifest, the 0th indexed element is always a
// manifest config.
if s.MediaType == configMediaType || (configMediaType == "" && i == 0 && isManifestMediaType(desc.MediaType)) {
// Add annotation for manifest config
if s.Annotations == nil {
s.Annotations = make(map[string]string)
Expand Down Expand Up @@ -158,3 +164,7 @@ func runPull(opts pullOptions) error {
fmt.Println("Digest:", desc.Digest)
return nil
}

func isManifestMediaType(mediaType string) bool {
return mediaType == docker.MediaTypeManifest || mediaType == ocispec.MediaTypeImageManifest
}
21 changes: 21 additions & 0 deletions internal/docker/mediatype.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright The ORAS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package docker

// docker media types
const (
MediaTypeManifest = "application/vnd.docker.distribution.manifest.v2+json"
)

0 comments on commit 4349084

Please sign in to comment.