From 861436bbe834856ed18a9aeb207508e65782214a Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Mon, 18 Apr 2022 15:10:21 -0400 Subject: [PATCH 1/2] layerStore.PutAdditionalLayer(): fix a copy/paste error We mistakenly mixed up the uncompressed and compressed digests when populating the by-uncompressed-digest map. Signed-off-by: Nalin Dahyabhai --- layers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layers.go b/layers.go index 5e9930ea78..15b96a26db 100644 --- a/layers.go +++ b/layers.go @@ -683,7 +683,7 @@ func (r *layerStore) PutAdditionalLayer(id string, parentLayer *Layer, names []s r.bycompressedsum[layer.CompressedDigest] = append(r.bycompressedsum[layer.CompressedDigest], layer.ID) } if layer.UncompressedDigest != "" { - r.byuncompressedsum[layer.CompressedDigest] = append(r.byuncompressedsum[layer.CompressedDigest], layer.ID) + r.byuncompressedsum[layer.UncompressedDigest] = append(r.byuncompressedsum[layer.UncompressedDigest], layer.ID) } if err := r.Save(); err != nil { r.driver.Remove(id) From 2de654ba2cb52d3a9e67009f48eb26e2c6973b39 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Mon, 18 Apr 2022 15:03:28 -0400 Subject: [PATCH 2/2] layerStore.Put(): update digest-based indexes when creating from templates When we're creating a layer using another layer as a template, add the new layer's uncompressed and compressed digest to the maps we use to index layers using those digests. When we forgot to do that, searching for a layer by either would still turn up the original template, so this didn't really break anything. Signed-off-by: Nalin Dahyabhai --- layers.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/layers.go b/layers.go index 15b96a26db..34d27ffa33 100644 --- a/layers.go +++ b/layers.go @@ -866,6 +866,14 @@ func (r *layerStore) Put(id string, parentLayer *Layer, names []string, mountLab return nil, -1, err } delete(layer.Flags, incompleteFlag) + } else { + // applyDiffWithOptions in the `diff != nil` case handles this bit for us + if layer.CompressedDigest != "" { + r.bycompressedsum[layer.CompressedDigest] = append(r.bycompressedsum[layer.CompressedDigest], layer.ID) + } + if layer.UncompressedDigest != "" { + r.byuncompressedsum[layer.UncompressedDigest] = append(r.byuncompressedsum[layer.UncompressedDigest], layer.ID) + } } err = r.Save() if err != nil {