Skip to content

Commit

Permalink
this does not work as is. I think we need to modify img utils.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joeybrown-sf committed Jul 12, 2024
1 parent dba6b9a commit c9516cd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cache/image_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io"
"runtime"
"strings"

"github.com/buildpacks/imgutil"
"github.com/buildpacks/imgutil/remote"
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit c9516cd

Please sign in to comment.