From c9516cd61831013f08fbd8832137d59a69332e8c Mon Sep 17 00:00:00 2001 From: Joey Brown Date: Thu, 11 Jul 2024 22:43:25 -0500 Subject: [PATCH] this does not work as is. I think we need to modify img utils. Image utils should fail with a Layer Not found in both ReuseLayer & GetLayer. For GetLayer, when there is a missing blob, it's return an unexpected EOF error. For ReuseLayer, when there is a missing blob, it's not returning an error but it should. --- cache/image_cache.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cache/image_cache.go b/cache/image_cache.go index 67a3437d..6e9de19c 100644 --- a/cache/image_cache.go +++ b/cache/image_cache.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "runtime" - "strings" "github.com/buildpacks/imgutil" "github.com/buildpacks/imgutil/remote" @@ -104,7 +103,14 @@ func (c *ImageCache) ReuseLayer(diffID string) error { if c.committed { return errCacheCommitted } - return c.newImage.ReuseLayer(diffID) + err := c.origImage.ReuseLayer(diffID) + if err != nil { + if IsLayerNotFound(err) { + return NewReadErr(fmt.Sprintf("failed to find cache layer with SHA '%s'", diffID)) + } + return fmt.Errorf("failed to reuse cache layer with SHA '%s'", diffID) + } + return nil } // IsLayerNotFound checks if the error is a layer not found error @@ -118,7 +124,7 @@ func (c *ImageCache) RetrieveLayer(diffID string) (io.ReadCloser, error) { closer, err := c.origImage.GetLayer(diffID) if err != nil { // TODO: This is a workaround for a bug in the imgutil library where it returns an error when the layer is not found - if IsLayerNotFound(err) || strings.Contains(err.Error(), "EOF") { + if IsLayerNotFound(err) { return nil, NewReadErr(fmt.Sprintf("failed to find cache layer with SHA '%s'", diffID)) } return nil, fmt.Errorf("failed to get cache layer with SHA '%s'", diffID)