MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / removeImagesFromCache

Function removeImagesFromCache

src/cmd/linuxkit/cache_clean.go:53–82  ·  view source on GitHub ↗

removeImagesFromCache removes images from the cache.

(images map[string]string, p *cachepkg.Provider, publishedOnly bool)

Source from the content-addressed store, hash-verified

51
52// removeImagesFromCache removes images from the cache.
53func removeImagesFromCache(images map[string]string, p *cachepkg.Provider, publishedOnly bool) {
54 // check each image in the registry. If it exists, remove it here.
55 for name, hash := range images {
56 if publishedOnly {
57 ref, err := namepkg.ParseReference(name)
58 if err != nil {
59 continue
60 }
61 desc, err := registry.GetRemote().Get(ref)
62 if err != nil {
63 log.Debugf("image %s not found in remote registry or error, leaving in cache: %v", name, err)
64 fmt.Fprintf(os.Stderr, "image %s not found in remote registry, leaving in cache", name)
65 continue
66 }
67 if desc == nil {
68 fmt.Fprintf(os.Stderr, "image %s not found in remote registry, leaving in cache", name)
69 continue
70 }
71 if desc.Digest.String() != hash {
72 fmt.Fprintf(os.Stderr, "image %s has mismatched hashes, cache %s vs remote registry %s, leaving in cache", name, hash, desc.Digest.String())
73 continue
74 }
75 }
76 // we have a match, remove it
77 fmt.Fprintf(os.Stderr, "removing image %s from cache", name)
78 if err := p.Remove(name); err != nil {
79 log.Warnf("Unable to remove image %s: %v", name, err)
80 }
81 }
82}

Callers 2

cacheCleanCmdFunction · 0.85
cacheRmCmdFunction · 0.85

Calls 3

RemoveMethod · 0.80
StringMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected