ApplyLayerWithOpts applies a single layer on top of the given provided layer chain, using the provided snapshotter, applier, and apply opts. If the layer was unpacked true is returned, if the layer already exists false is returned.
(ctx context.Context, layer Layer, chain []digest.Digest, sn snapshots.Snapshotter, a diff.Applier, opts []snapshots.Opt, applyOpts []diff.ApplyOpt)
| 89 | // using the provided snapshotter, applier, and apply opts. If the layer was unpacked true |
| 90 | // is returned, if the layer already exists false is returned. |
| 91 | func ApplyLayerWithOpts(ctx context.Context, layer Layer, chain []digest.Digest, sn snapshots.Snapshotter, a diff.Applier, opts []snapshots.Opt, applyOpts []diff.ApplyOpt) (bool, error) { |
| 92 | var ( |
| 93 | chainID = identity.ChainID(append(chain, layer.Diff.Digest)).String() |
| 94 | applied bool |
| 95 | ) |
| 96 | if _, err := sn.Stat(ctx, chainID); err != nil { |
| 97 | if !errdefs.IsNotFound(err) { |
| 98 | return false, fmt.Errorf("failed to stat snapshot %s: %w", chainID, err) |
| 99 | } |
| 100 | |
| 101 | if err := applyLayers(ctx, []Layer{layer}, append(chain, layer.Diff.Digest), sn, a, opts, applyOpts); err != nil { |
| 102 | if !errdefs.IsAlreadyExists(err) { |
| 103 | return false, err |
| 104 | } |
| 105 | } else { |
| 106 | applied = true |
| 107 | } |
| 108 | } |
| 109 | return applied, nil |
| 110 | |
| 111 | } |
| 112 | |
| 113 | func applyLayers(ctx context.Context, layers []Layer, chain []digest.Digest, sn snapshots.Snapshotter, a diff.Applier, opts []snapshots.Opt, applyOpts []diff.ApplyOpt) error { |
| 114 | var ( |
no test coverage detected
searching dependent graphs…