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)
| 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. |
| 34 | func 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 | } |