diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-09-07 11:26:11 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-09-07 11:28:58 +0200 |
commit | 238abf6e2171f344bbb0ee2233a3e1f6b585ebb0 (patch) | |
tree | 6ebb0ad845d3bc9809d8e47d9f6d200de66a3d8a /libpod/image | |
parent | ba8d0bb5e336e84aaf68148563e61558b5dc94f5 (diff) | |
download | podman-238abf6e2171f344bbb0ee2233a3e1f6b585ebb0.tar.gz podman-238abf6e2171f344bbb0ee2233a3e1f6b585ebb0.tar.bz2 podman-238abf6e2171f344bbb0ee2233a3e1f6b585ebb0.zip |
make image parent check more robust
Follow up on issue #7444 and make the parent checks more robust.
We can end up with an incoherent storage when, for instance, a
build has been killed.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'libpod/image')
-rw-r--r-- | libpod/image/image.go | 13 | ||||
-rw-r--r-- | libpod/image/layer_tree.go | 4 |
2 files changed, 11 insertions, 6 deletions
diff --git a/libpod/image/image.go b/libpod/image/image.go index dee2ce0ee..2d055cc44 100644 --- a/libpod/image/image.go +++ b/libpod/image/image.go @@ -1247,11 +1247,14 @@ func areParentAndChild(parent, child *imgspecv1.Image) bool { // candidate parent's diff IDs, which together would have // controlled which layers were used - // issue #7444 describes a panic where the length of child.RootFS.DiffIDs - // is checked but child is nil. Adding a simple band-aid approach to prevent - // the problem until the origin of the problem can be worked out in the issue - // itself. - if child == nil || len(parent.RootFS.DiffIDs) > len(child.RootFS.DiffIDs) { + // Both, child and parent, may be nil when the storage is left in an + // incoherent state. Issue #7444 describes such a case when a build + // has been killed. + if child == nil || parent == nil { + return false + } + + if len(parent.RootFS.DiffIDs) > len(child.RootFS.DiffIDs) { return false } childUsesCandidateDiffs := true diff --git a/libpod/image/layer_tree.go b/libpod/image/layer_tree.go index 3699655fd..18101575e 100644 --- a/libpod/image/layer_tree.go +++ b/libpod/image/layer_tree.go @@ -32,7 +32,9 @@ func (t *layerTree) toOCI(ctx context.Context, i *Image) (*ociv1.Image, error) { oci, exists := t.ociCache[i.ID()] if !exists { oci, err = i.ociv1Image(ctx) - t.ociCache[i.ID()] = oci + if err == nil { + t.ociCache[i.ID()] = oci + } } return oci, err } |