MCPcopy Create free account
hub / github.com/containerd/nerdctl / applyDiffLayer

Function applyDiffLayer

pkg/imgutil/commit/commit.go:533–565  ·  view source on GitHub ↗

applyDiffLayer will apply diff layer content created by createDiff into the snapshotter.

(ctx context.Context, name string, baseImg ocispec.Image, sn snapshots.Snapshotter, differ diff.Applier, diffDesc ocispec.Descriptor)

Source from the content-addressed store, hash-verified

531
532// applyDiffLayer will apply diff layer content created by createDiff into the snapshotter.
533func applyDiffLayer(ctx context.Context, name string, baseImg ocispec.Image, sn snapshots.Snapshotter, differ diff.Applier, diffDesc ocispec.Descriptor) (retErr error) {
534 var (
535 key = uniquePart() + "-" + name
536 parent = identity.ChainID(baseImg.RootFS.DiffIDs).String()
537 )
538
539 mount, err := sn.Prepare(ctx, key, parent)
540 if err != nil {
541 return err
542 }
543
544 defer func() {
545 if retErr != nil {
546 // NOTE: the snapshotter should be hold by lease. Even
547 // if the cleanup fails, the containerd gc can delete it.
548 if err := sn.Remove(ctx, key); err != nil {
549 log.G(ctx).Warnf("failed to cleanup aborted apply %s: %s", key, err)
550 }
551 }
552 }()
553
554 if _, err = differ.Apply(ctx, diffDesc, mount); err != nil {
555 return err
556 }
557
558 if err = sn.Commit(ctx, name, key); err != nil {
559 if errdefs.IsAlreadyExists(err) {
560 return nil
561 }
562 return err
563 }
564 return nil
565}
566
567// copied from github.com/containerd/containerd/rootfs/apply.go
568func uniquePart() string {

Callers 1

CommitFunction · 0.85

Calls 3

uniquePartFunction · 0.85
RemoveMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…