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

Method layerTree

libimage/layer_tree.go:78–127  ·  view source on GitHub ↗

layerTree extracts a layerTree from the layers in the local storage and relates them to the specified images.

()

Source from the content-addressed store, hash-verified

76// layerTree extracts a layerTree from the layers in the local storage and
77// relates them to the specified images.
78func (r *Runtime) layerTree() (*layerTree, error) {
79 layers, err := r.store.Layers()
80 if err != nil {
81 return nil, err
82 }
83
84 images, err := r.ListImages(context.Background(), nil, nil)
85 if err != nil {
86 return nil, err
87 }
88
89 tree := layerTree{
90 nodes: make(map[string]*layerNode),
91 ociCache: make(map[string]*ociv1.Image),
92 }
93
94 // First build a tree purely based on layer information.
95 for i := range layers {
96 node := tree.node(layers[i].ID)
97 node.layer = &layers[i]
98 if layers[i].Parent == "" {
99 continue
100 }
101 parent := tree.node(layers[i].Parent)
102 node.parent = parent
103 parent.children = append(parent.children, node)
104 }
105
106 // Now assign the images to each (top) layer.
107 for i := range images {
108 img := images[i] // do not leak loop variable outside the scope
109 topLayer := img.TopLayer()
110 if topLayer == "" {
111 tree.emptyImages = append(tree.emptyImages, img)
112 continue
113 }
114 node, exists := tree.nodes[topLayer]
115 if !exists {
116 // Note: erroring out in this case has turned out having been a
117 // mistake. Users may not be able to recover, so we're now
118 // throwing a warning to guide them to resolve the issue and
119 // turn the errors non-fatal.
120 logrus.Warnf("Top layer %s of image %s not found in layer tree. The storage may be corrupted, consider running `podman system reset`.", topLayer, img.ID())
121 continue
122 }
123 node.images = append(node.images, img)
124 }
125
126 return &tree, nil
127}
128
129// children returns the child images of parent. Child images are images with
130// either the same top layer as parent or parent being the true parent layer.

Callers 6

compileImageFiltersMethod · 0.95
DiskUsageMethod · 0.95
ParentMethod · 0.80
getChildrenMethod · 0.80
HistoryMethod · 0.80
TreeMethod · 0.80

Calls 4

ListImagesMethod · 0.95
nodeMethod · 0.95
TopLayerMethod · 0.80
IDMethod · 0.45

Tested by

no test coverage detected