MCPcopy
hub / github.com/docker/compose / filterImagesByExistence

Method filterImagesByExistence

pkg/compose/image_pruner.go:194–219  ·  view source on GitHub ↗

filterImagesByExistence returns the subset of images that exist in the engine store. NOTE: Any transient errors communicating with the API will result in an image being returned as "existing", as this method is exclusively used to find images to remove, so the worst case of being conservative here

(ctx context.Context, imageNames []string)

Source from the content-addressed store, hash-verified

192// attempt to remove an image that doesn't exist, which will cause a warning
193// but is otherwise harmless.
194func (p *ImagePruner) filterImagesByExistence(ctx context.Context, imageNames []string) ([]string, error) {
195 var mu sync.Mutex
196 var ret []string
197
198 eg, ctx := errgroup.WithContext(ctx)
199 for _, img := range imageNames {
200 eg.Go(func() error {
201 _, err := p.client.ImageInspect(ctx, img)
202 if errdefs.IsNotFound(err) {
203 // err on the side of caution: only skip if we successfully
204 // queried the API and got back a definitive "not exists"
205 return nil
206 }
207 mu.Lock()
208 defer mu.Unlock()
209 ret = append(ret, img)
210 return nil
211 })
212 }
213
214 if err := eg.Wait(); err != nil {
215 return nil, err
216 }
217
218 return ret, nil
219}
220
221// normalizeAndDedupeImages returns the unique set of images after normalization.
222func normalizeAndDedupeImages(images []string) []string {

Callers 2

namedImagesMethod · 0.95
unlabeledLocalImagesMethod · 0.95

Calls 3

WaitMethod · 0.65
ImageInspectMethod · 0.45
LockMethod · 0.45

Tested by

no test coverage detected