github.com/moby/docker@v26.1.3+incompatible/daemon/containerd/handlers.go (about) 1 package containerd 2 3 import ( 4 "context" 5 6 "github.com/containerd/containerd/content" 7 cerrdefs "github.com/containerd/containerd/errdefs" 8 containerdimages "github.com/containerd/containerd/images" 9 ocispec "github.com/opencontainers/image-spec/specs-go/v1" 10 ) 11 12 // walkPresentChildren is a simple wrapper for containerdimages.Walk with presentChildrenHandler. 13 // This is only a convenient helper to reduce boilerplate. 14 func (i *ImageService) walkPresentChildren(ctx context.Context, target ocispec.Descriptor, f func(context.Context, ocispec.Descriptor) error) error { 15 return containerdimages.Walk(ctx, presentChildrenHandler(i.content, containerdimages.HandlerFunc( 16 func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { 17 return nil, f(ctx, desc) 18 })), target) 19 } 20 21 // presentChildrenHandler is a handler wrapper which traverses all children 22 // descriptors that are present in the store and calls specified handler. 23 func presentChildrenHandler(store content.Store, h containerdimages.HandlerFunc) containerdimages.HandlerFunc { 24 return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { 25 _, err := store.Info(ctx, desc.Digest) 26 if err != nil { 27 if cerrdefs.IsNotFound(err) { 28 return nil, nil 29 } 30 return nil, err 31 } 32 33 children, err := h(ctx, desc) 34 if err != nil { 35 return nil, err 36 } 37 38 c, err := containerdimages.Children(ctx, store, desc) 39 if err != nil { 40 return nil, err 41 } 42 children = append(children, c...) 43 44 return children, nil 45 } 46 }