ApplyLayersWithOpts applies all the layers using the given snapshotter, applier, and apply opts. The returned result is a chain id digest representing all the applied layers. Layers are applied in order they are given, making the first layer the bottom-most layer in the layer chain.
(ctx context.Context, layers []Layer, sn snapshots.Snapshotter, a diff.Applier, applyOpts []diff.ApplyOpt)
| 55 | // Layers are applied in order they are given, making the first layer the |
| 56 | // bottom-most layer in the layer chain. |
| 57 | func ApplyLayersWithOpts(ctx context.Context, layers []Layer, sn snapshots.Snapshotter, a diff.Applier, applyOpts []diff.ApplyOpt) (digest.Digest, error) { |
| 58 | chain := make([]digest.Digest, len(layers)) |
| 59 | for i, layer := range layers { |
| 60 | chain[i] = layer.Diff.Digest |
| 61 | } |
| 62 | chainID := identity.ChainID(chain) |
| 63 | |
| 64 | // Just stat top layer, remaining layers will have their existence checked |
| 65 | // on prepare. Calling prepare on upper layers first guarantees that upper |
| 66 | // layers are not removed while calling stat on lower layers |
| 67 | _, err := sn.Stat(ctx, chainID.String()) |
| 68 | if err != nil { |
| 69 | if !errdefs.IsNotFound(err) { |
| 70 | return "", fmt.Errorf("failed to stat snapshot %s: %w", chainID, err) |
| 71 | } |
| 72 | |
| 73 | if err := applyLayers(ctx, layers, chain, sn, a, nil, applyOpts); err != nil && !errdefs.IsAlreadyExists(err) { |
| 74 | return "", err |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return chainID, nil |
| 79 | } |
| 80 | |
| 81 | // ApplyLayer applies a single layer on top of the given provided layer chain, |
| 82 | // using the provided snapshotter and applier. If the layer was unpacked true |
no test coverage detected
searching dependent graphs…