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)
| 531 | |
| 532 | // applyDiffLayer will apply diff layer content created by createDiff into the snapshotter. |
| 533 | func 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 |
| 568 | func uniquePart() string { |
no test coverage detected
searching dependent graphs…