MCPcopy
hub / github.com/containerd/containerd / CreateDiff

Function CreateDiff

pkg/rootfs/diff.go:34–67  ·  view source on GitHub ↗

CreateDiff creates a layer diff for the given snapshot identifier from the parent of the snapshot. A content ref is provided to track the progress of the content creation and the provided snapshotter and mount differ are used for calculating the diff. The descriptor for the layer diff is returned.

(ctx context.Context, snapshotID string, sn snapshots.Snapshotter, d diff.Comparer, opts ...diff.Opt)

Source from the content-addressed store, hash-verified

32// the content creation and the provided snapshotter and mount differ are used
33// for calculating the diff. The descriptor for the layer diff is returned.
34func CreateDiff(ctx context.Context, snapshotID string, sn snapshots.Snapshotter, d diff.Comparer, opts ...diff.Opt) (ocispec.Descriptor, error) {
35 info, err := sn.Stat(ctx, snapshotID)
36 if err != nil {
37 return ocispec.Descriptor{}, err
38 }
39
40 lowerKey := fmt.Sprintf("%s-parent-view-%s", info.Parent, uniquePart())
41 lower, err := sn.View(ctx, lowerKey, info.Parent)
42 if err != nil {
43 return ocispec.Descriptor{}, err
44 }
45 defer cleanup.Do(ctx, func(ctx context.Context) {
46 sn.Remove(ctx, lowerKey)
47 })
48
49 var upper []mount.Mount
50 if info.Kind == snapshots.KindActive {
51 upper, err = sn.Mounts(ctx, snapshotID)
52 if err != nil {
53 return ocispec.Descriptor{}, err
54 }
55 } else {
56 upperKey := fmt.Sprintf("%s-view-%s", snapshotID, uniquePart())
57 upper, err = sn.View(ctx, upperKey, snapshotID)
58 if err != nil {
59 return ocispec.Descriptor{}, err
60 }
61 defer cleanup.Do(ctx, func(ctx context.Context) {
62 sn.Remove(ctx, upperKey)
63 })
64 }
65
66 return d.Compare(ctx, lower, upper, opts...)
67}

Callers 3

WithCheckpointRWFunction · 0.92
checkpointRWSnapshotMethod · 0.92
snapshots.goFile · 0.92

Calls 7

DoFunction · 0.92
uniquePartFunction · 0.70
StatMethod · 0.65
ViewMethod · 0.65
RemoveMethod · 0.65
MountsMethod · 0.65
CompareMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…