MCPcopy Create free account
hub / github.com/containers/common / parent

Method parent

libimage/layer_tree.go:235–299  ·  view source on GitHub ↗

parent returns the parent image or nil if no parent image could be found. Note that manifest lists do not have parents.

(ctx context.Context, child *Image)

Source from the content-addressed store, hash-verified

233// parent returns the parent image or nil if no parent image could be found.
234// Note that manifest lists do not have parents.
235func (t *layerTree) parent(ctx context.Context, child *Image) (*Image, error) {
236 if child.TopLayer() == "" {
237 if isManifestList, _ := child.IsManifestList(ctx); isManifestList {
238 return nil, nil
239 }
240 }
241
242 childID := child.ID()
243 childOCI, err := t.toOCI(ctx, child)
244 if err != nil {
245 return nil, err
246 }
247
248 // Empty images are special in that they do not have any physical layer
249 // but yet can have a parent-child relation. Hence, compare the
250 // "child" image to all other known empty images.
251 if child.TopLayer() == "" {
252 for _, empty := range t.emptyImages {
253 if childID == empty.ID() {
254 continue
255 }
256 emptyOCI, err := t.toOCI(ctx, empty)
257 if err != nil {
258 return nil, err
259 }
260 // History check.
261 if areParentAndChild(emptyOCI, childOCI) {
262 return empty, nil
263 }
264 }
265 return nil, nil
266 }
267
268 node, exists := t.nodes[child.TopLayer()]
269 if !exists {
270 // Note: erroring out in this case has turned out having been a
271 // mistake. Users may not be able to recover, so we're now
272 // throwing a warning to guide them to resolve the issue and
273 // turn the errors non-fatal.
274 logrus.Warnf("Layer %s not found in layer tree. The storage may be corrupted, consider running `podman system reset`.", child.TopLayer())
275 return nil, nil
276 }
277
278 // Check images from the parent node (i.e., parent layer) and images
279 // with the same layer (i.e., same top layer).
280 images := node.images
281 if node.parent != nil {
282 images = append(images, node.parent.images...)
283 }
284 for _, parent := range images {
285 if parent.ID() == childID {
286 continue
287 }
288 parentOCI, err := t.toOCI(ctx, parent)
289 if err != nil {
290 return nil, err
291 }
292 // History check.

Callers 2

ParentMethod · 0.80
diskUsageForImageFunction · 0.80

Calls 5

toOCIMethod · 0.95
areParentAndChildFunction · 0.85
TopLayerMethod · 0.80
IsManifestListMethod · 0.80
IDMethod · 0.45

Tested by

no test coverage detected