MCPcopy
hub / github.com/containerd/containerd / Compare

Method Compare

plugins/diff/windows/windows.go:174–310  ·  view source on GitHub ↗

Compare creates a diff between the given mounts and uploads the result to the content store.

(ctx context.Context, lower, upper []mount.Mount, opts ...diff.Opt)

Source from the content-addressed store, hash-verified

172// Compare creates a diff between the given mounts and uploads the result
173// to the content store.
174func (s windowsDiff) Compare(ctx context.Context, lower, upper []mount.Mount, opts ...diff.Opt) (d ocispec.Descriptor, err error) {
175 t1 := time.Now()
176
177 var config diff.Config
178 for _, opt := range opts {
179 if err := opt(&config); err != nil {
180 return emptyDesc, err
181 }
182 }
183 if tm := epoch.FromContext(ctx); tm != nil && config.SourceDateEpoch == nil {
184 config.SourceDateEpoch = tm
185 }
186
187 layers, err := mountPairToLayerStack(lower, upper)
188 if err != nil {
189 return emptyDesc, err
190 }
191
192 if config.MediaType == "" {
193 config.MediaType = ocispec.MediaTypeImageLayerGzip
194 }
195
196 compressionType := compression.Uncompressed
197 switch config.MediaType {
198 case ocispec.MediaTypeImageLayer:
199 case ocispec.MediaTypeImageLayerGzip:
200 compressionType = compression.Gzip
201 case ocispec.MediaTypeImageLayerZstd:
202 compressionType = compression.Zstd
203 default:
204 return emptyDesc, fmt.Errorf("unsupported diff media type: %v: %w", config.MediaType, errdefs.ErrNotImplemented)
205 }
206
207 newReference := false
208 if config.Reference == "" {
209 newReference = true
210 config.Reference = uniqueRef()
211 }
212
213 cw, err := s.store.Writer(ctx, content.WithRef(config.Reference), content.WithDescriptor(ocispec.Descriptor{
214 MediaType: config.MediaType,
215 }))
216
217 if err != nil {
218 return emptyDesc, fmt.Errorf("failed to open writer: %w", err)
219 }
220
221 defer func() {
222 if err != nil {
223 cw.Close()
224 if newReference {
225 if abortErr := s.store.Abort(ctx, config.Reference); abortErr != nil {
226 log.G(ctx).WithError(abortErr).WithField("ref", config.Reference).Warnf("failed to delete diff upload")
227 }
228 }
229 }
230 }()
231

Callers

nothing calls this directly

Calls 15

FromContextFunction · 0.92
WithRefFunction · 0.92
WithDescriptorFunction · 0.92
CompressStreamFunction · 0.92
WriteDiffFunction · 0.92
WithParentLayersFunction · 0.92
WithLabelsFunction · 0.92
mountPairToLayerStackFunction · 0.85
uniqueRefFunction · 0.70
WriterMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected