github.com/rawahars/moby@v24.0.4+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 store := i.client.ContentStore() 16 return containerdimages.Walk(ctx, presentChildrenHandler(store, containerdimages.HandlerFunc( 17 func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { 18 return nil, f(ctx, desc) 19 })), target) 20 } 21 22 // presentChildrenHandler is a handler wrapper which traverses all children 23 // descriptors that are present in the store and calls specified handler. 24 func presentChildrenHandler(store content.Store, h containerdimages.HandlerFunc) containerdimages.HandlerFunc { 25 return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) { 26 _, err := store.Info(ctx, desc.Digest) 27 if err != nil { 28 if cerrdefs.IsNotFound(err) { 29 return nil, nil 30 } 31 return nil, err 32 } 33 34 children, err := h(ctx, desc) 35 if err != nil { 36 return nil, err 37 } 38 39 c, err := containerdimages.Children(ctx, store, desc) 40 if err != nil { 41 return nil, err 42 } 43 children = append(children, c...) 44 45 return children, nil 46 } 47 }