Skip to content

Commit

Permalink
Merge branch 'main' into errors-repo
Browse files Browse the repository at this point in the history
  • Loading branch information
sajayantony authored Nov 6, 2023
2 parents b165516 + 94e32e8 commit 48ce099
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
22 changes: 14 additions & 8 deletions cmd/oras/root/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"sync"
"sync/atomic"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -130,7 +131,7 @@ func runPull(ctx context.Context, opts pullOptions) error {
dst.AllowPathTraversalOnWrite = opts.PathTraversal
dst.DisableOverwrite = opts.KeepOldFiles

desc, skippedLayers, err := doPull(ctx, src, dst, copyOptions, &opts)
desc, layerSkipped, err := doPull(ctx, src, dst, copyOptions, &opts)
if err != nil {
if errors.Is(err, file.ErrPathTraversalDisallowed) {
err = fmt.Errorf("%s: %w", "use flag --allow-path-traversal to allow insecurely pulling files outside of working directory", err)
Expand All @@ -139,7 +140,7 @@ func runPull(ctx context.Context, opts pullOptions) error {
}

// suggest oras copy for pulling layers without annotation
if skippedLayers > 0 {
if layerSkipped {
fmt.Printf("Skipped pulling layers without file name in %q\n", ocispec.AnnotationTitle)
fmt.Printf("Use 'oras copy %s --to-oci-layout <layout-dir>' to pull all layers.\n", opts.RawReference)
} else {
Expand All @@ -149,13 +150,13 @@ func runPull(ctx context.Context, opts pullOptions) error {
return nil
}

func doPull(ctx context.Context, src oras.ReadOnlyTarget, dst oras.GraphTarget, opts oras.CopyOptions, po *pullOptions) (ocispec.Descriptor, int, error) {
func doPull(ctx context.Context, src oras.ReadOnlyTarget, dst oras.GraphTarget, opts oras.CopyOptions, po *pullOptions) (ocispec.Descriptor, bool, error) {
var configPath, configMediaType string
var err error
if po.ManifestConfigRef != "" {
configPath, configMediaType, err = fileref.Parse(po.ManifestConfigRef, "")
if err != nil {
return ocispec.Descriptor{}, 0, err
return ocispec.Descriptor{}, false, err
}
}

Expand All @@ -171,12 +172,12 @@ func doPull(ctx context.Context, src oras.ReadOnlyTarget, dst oras.GraphTarget,
var tracked track.GraphTarget
dst, tracked, err = getTrackedTarget(dst, po.TTY, "Downloading", "Pulled ")
if err != nil {
return ocispec.Descriptor{}, 0, err
return ocispec.Descriptor{}, false, err
}
if tracked != nil {
defer tracked.Close()
}
skippedLayers := 0
var layerSkipped atomic.Bool
var printed sync.Map
var getConfigOnce sync.Once
opts.FindSuccessors = func(ctx context.Context, fetcher content.Fetcher, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
Expand Down Expand Up @@ -231,7 +232,12 @@ func doPull(ctx context.Context, src oras.ReadOnlyTarget, dst oras.GraphTarget,
for _, s := range nodes {
if s.Annotations[ocispec.AnnotationTitle] == "" {
if content.Equal(s, ocispec.DescriptorEmptyJSON) {
skippedLayers++
// empty layer
continue
}
if s.Annotations[ocispec.AnnotationTitle] == "" {
// unnamed layers are skipped
layerSkipped.Store(true)
}
ss, err := content.Successors(ctx, fetcher, s)
if err != nil {
Expand Down Expand Up @@ -288,7 +294,7 @@ func doPull(ctx context.Context, src oras.ReadOnlyTarget, dst oras.GraphTarget,

// Copy
desc, err := oras.Copy(ctx, src, po.Reference, dst, po.Reference, opts)
return desc, skippedLayers, err
return desc, layerSkipped.Load(), err
}

// generateContentKey generates a unique key for each content descriptor, using
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
golang.org/x/sync v0.4.0
golang.org/x/sync v0.5.0
golang.org/x/term v0.13.0
gopkg.in/yaml.v3 v3.0.1
oras.land/oras-go/v2 v2.3.1-0.20231026053328-062ed0e058f8
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
Expand Down

0 comments on commit 48ce099

Please sign in to comment.