MCPcopy
hub / github.com/containerd/containerd / applyCIMLayerCommon

Function applyCIMLayerCommon

plugins/diff/windows/cimfs.go:254–311  ·  view source on GitHub ↗

applyCimFSCommon is a common function used for applying all diffs to a cim layer.

(ctx context.Context, desc ocispec.Descriptor, store content.Store, applyFunc cimApplyFunc, opts ...diff.ApplyOpt)

Source from the content-addressed store, hash-verified

252
253// applyCimFSCommon is a common function used for applying all diffs to a cim layer.
254func applyCIMLayerCommon(ctx context.Context, desc ocispec.Descriptor, store content.Store, applyFunc cimApplyFunc, opts ...diff.ApplyOpt) (_ ocispec.Descriptor, err error) {
255 var config diff.ApplyConfig
256 for _, o := range opts {
257 if err := o(ctx, desc, &config); err != nil {
258 return emptyDesc, fmt.Errorf("failed to apply config opt: %w", err)
259 }
260 }
261
262 t1 := time.Now()
263 defer func() {
264 if err == nil {
265 log.G(ctx).WithFields(log.Fields{
266 "d": time.Since(t1),
267 "digest": desc.Digest,
268 "size": desc.Size,
269 "media": desc.MediaType,
270 }).Debug("diff applied")
271 }
272 }()
273
274 ra, err := store.ReaderAt(ctx, desc)
275 if err != nil {
276 return emptyDesc, fmt.Errorf("failed to get reader from content store: %w", err)
277 }
278 defer ra.Close()
279
280 processor := diff.NewProcessorChain(desc.MediaType, content.NewReader(ra))
281 for {
282 if processor, err = diff.GetProcessor(ctx, processor, config.ProcessorPayloads); err != nil {
283 return emptyDesc, fmt.Errorf("failed to get stream processor for %s: %w", desc.MediaType, err)
284 }
285 if processor.MediaType() == ocispec.MediaTypeImageLayer {
286 break
287 }
288 }
289 defer processor.Close()
290
291 digester := digest.Canonical.Digester()
292 rc := &readCounter{
293 r: io.TeeReader(processor, digester.Hash()),
294 }
295
296 if _, err = applyFunc(ctx, rc); err != nil {
297 return emptyDesc, err
298 }
299
300 // Read any trailing data
301 if _, err := io.Copy(io.Discard, rc); err != nil {
302 return emptyDesc, err
303 }
304
305 return ocispec.Descriptor{
306 MediaType: ocispec.MediaTypeImageLayer,
307 Size: rc.c,
308 Digest: digester.Digest(),
309 }, nil
310
311}

Callers 2

ApplyMethod · 0.85
ApplyMethod · 0.85

Calls 8

NewProcessorChainFunction · 0.92
NewReaderFunction · 0.92
GetProcessorFunction · 0.92
CopyMethod · 0.80
ReaderAtMethod · 0.65
CloseMethod · 0.65
MediaTypeMethod · 0.65
DigestMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…