MCPcopy
hub / github.com/moby/moby / applyLayer

Function applyLayer

daemon/pkg/plugin/fetch_linux.go:120–149  ·  view source on GitHub ↗

applyLayer makes an c8dimages.HandlerFunc which applies a fetched image rootfs layer to a directory. TODO(@cpuguy83) This gets run sequentially after layer pull (makes sense), however if there are multiple layers to fetch we may end up extracting layers in the wrong order.

(cs content.Store, dir string, out progress.Output)

Source from the content-addressed store, hash-verified

118// if there are multiple layers to fetch we may end up extracting layers in the wrong
119// order.
120func applyLayer(cs content.Store, dir string, out progress.Output) c8dimages.HandlerFunc {
121 return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
122 switch desc.MediaType {
123 case
124 ocispec.MediaTypeImageLayer,
125 c8dimages.MediaTypeDockerSchema2Layer,
126 ocispec.MediaTypeImageLayerGzip,
127 c8dimages.MediaTypeDockerSchema2LayerGzip:
128 default:
129 return nil, nil
130 }
131
132 ra, err := cs.ReaderAt(ctx, desc)
133 if err != nil {
134 return nil, errors.Wrapf(err, "error getting content from content store for digest %s", desc.Digest)
135 }
136
137 id := stringid.TruncateID(desc.Digest.String())
138
139 rc := ioutils.NewReadCloserWrapper(content.NewReader(ra), ra.Close)
140 pr := progress.NewProgressReader(rc, out, desc.Size, id, "Extracting")
141 defer pr.Close()
142
143 if _, err := chrootarchive.ApplyLayer(dir, pr); err != nil {
144 return nil, errors.Wrapf(err, "error applying layer for digest %s", desc.Digest)
145 }
146 progress.Update(out, id, "Complete")
147 return nil, nil
148 }
149}
150
151func childrenHandler(cs content.Store) c8dimages.HandlerFunc {
152 ch := c8dimages.ChildrenHandler(cs)

Callers 2

UpgradeMethod · 0.85
PullMethod · 0.85

Calls 7

TruncateIDFunction · 0.92
NewReadCloserWrapperFunction · 0.92
NewProgressReaderFunction · 0.92
UpdateFunction · 0.92
ReaderAtMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…