removeImagesFromCache removes images from the cache.
(images map[string]string, p *cachepkg.Provider, publishedOnly bool)
| 51 | |
| 52 | // removeImagesFromCache removes images from the cache. |
| 53 | func 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 | } |
no test coverage detected