Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
Signed-off-by: Joey Brown <[email protected]>
  • Loading branch information
joeybrown-sf committed Jul 2, 2024
1 parent 376931a commit 1c4aefa
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cache/caching_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

"github.com/buildpacks/imgutil"
"github.com/buildpacks/imgutil/fakes"
"github.com/buildpacks/lifecycle/cmd"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpacks/lifecycle/cmd"

"github.com/buildpacks/lifecycle/cache"
h "github.com/buildpacks/lifecycle/testhelpers"
)
Expand Down
4 changes: 4 additions & 0 deletions cache/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ import (

var errCacheCommitted = errors.New("cache cannot be modified after commit")

// ReadErr is an error type for filesystem read errors.
type ReadErr struct {
msg string
}

// NewReadErr creates a new ReadErr.
func NewReadErr(msg string) ReadErr {
return ReadErr{msg: msg}
}

// Error returns the error message.
func (e ReadErr) Error() string {
return e.msg
}

// IsReadErr checks if an error is a ReadErr.
func IsReadErr(err error) (bool, *ReadErr) {
var e ReadErr
isReadErr := errors.As(err, &e)
Expand Down
4 changes: 4 additions & 0 deletions cache/image_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ func (c *ImageCache) ReuseLayer(diffID string) error {
return c.newImage.ReuseLayer(diffID)
}

// IsLayerNotFound checks if the error is a layer not found error
func IsLayerNotFound(err error) bool {
var e imgutil.ErrLayerNotFound
return errors.As(err, &e)
}

// RetrieveLayer retrieves a layer from the cache
func (c *ImageCache) RetrieveLayer(diffID string) (io.ReadCloser, error) {
closer, err := c.origImage.GetLayer(diffID)
if err != nil {
Expand Down Expand Up @@ -142,6 +144,7 @@ func (c *ImageCache) Commit() error {
return nil
}

// LayerExists checks if a layer exists in the cache
func (c *ImageCache) LayerExists(diffID string) (bool, error) {
layers, err := c.origImage.UnderlyingImage().Layers()
if err != nil {
Expand All @@ -161,6 +164,7 @@ func (c *ImageCache) LayerExists(diffID string) (bool, error) {
return false, nil
}

// Destroy deletes the cache image
func (c *ImageCache) Destroy() {
c.imageDeleter.DeleteImage(c.origImage)
}
6 changes: 5 additions & 1 deletion cache/volume_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"runtime"
"strings"

"github.com/buildpacks/lifecycle/log"
"github.com/pkg/errors"

"github.com/buildpacks/lifecycle/log"

"github.com/buildpacks/lifecycle/internal/fsutil"
"github.com/buildpacks/lifecycle/platform"
)
Expand All @@ -25,6 +26,7 @@ type VolumeCache struct {
logger log.Logger
}

// NewVolumeCache creates a new VolumeCache
func NewVolumeCache(dir string, logger log.Logger) (*VolumeCache, error) {
if _, err := os.Stat(dir); err != nil {
return nil, err
Expand Down Expand Up @@ -227,6 +229,7 @@ func (c *VolumeCache) setupStagingDir() error {
return os.MkdirAll(c.stagingDir, 0777)
}

// LayerExists returns true if the layer with the given diffID exists in the cache
func (c *VolumeCache) LayerExists(diffID string) (bool, error) {
path := diffIDPath(c.committedDir, diffID)
if _, err := os.Stat(path); err != nil {
Expand All @@ -238,6 +241,7 @@ func (c *VolumeCache) LayerExists(diffID string) (bool, error) {
return true, nil
}

// Destroy removes the cache directory and all its contents
func (c *VolumeCache) Destroy() {
if err := os.RemoveAll(c.dir); err != nil {
c.logger.Warnf("Unable to delete cache directory: %v", err.Error())
Expand Down
5 changes: 3 additions & 2 deletions cache/volume_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"path/filepath"
"testing"

"github.com/buildpacks/lifecycle/cmd"
"github.com/buildpacks/lifecycle/log"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpacks/lifecycle/cmd"
"github.com/buildpacks/lifecycle/log"

"github.com/buildpacks/lifecycle/buildpack"
"github.com/buildpacks/lifecycle/cache"
"github.com/buildpacks/lifecycle/platform"
Expand Down
3 changes: 2 additions & 1 deletion cmd/lifecycle/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
"github.com/buildpacks/imgutil/layout"
"github.com/buildpacks/imgutil/local"
"github.com/buildpacks/imgutil/remote"
"github.com/buildpacks/lifecycle/log"
"github.com/docker/docker/client"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"

"github.com/buildpacks/lifecycle/log"

"github.com/buildpacks/lifecycle/auth"
"github.com/buildpacks/lifecycle/buildpack"
"github.com/buildpacks/lifecycle/cache"
Expand Down
3 changes: 1 addition & 2 deletions phase/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ func (e *Exporter) addOrReuseCacheLayer(cache Cache, layerDir LayerDir, previous
isReadErr, readErr := c.IsReadErr(err)
if !isReadErr {
return "", errors.Wrapf(err, "reusing layer %s", layer.ID)
} else {
e.Logger.Warnf("%s, skipping reuse", readErr.Error())
}
e.Logger.Warnf("%s, skipping reuse", readErr.Error())
}
}
e.Logger.Infof("Adding cache layer '%s'\n", layer.ID)
Expand Down
1 change: 1 addition & 0 deletions phase/connected_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/buildpacks/imgutil"

"github.com/buildpacks/lifecycle/log"

"github.com/buildpacks/lifecycle/api"
Expand Down
3 changes: 2 additions & 1 deletion phase/restorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package phase
import (
"path/filepath"

c "github.com/buildpacks/lifecycle/cache"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"

c "github.com/buildpacks/lifecycle/cache"

"github.com/buildpacks/lifecycle/api"
"github.com/buildpacks/lifecycle/buildpack"
"github.com/buildpacks/lifecycle/internal/layer"
Expand Down

0 comments on commit 1c4aefa

Please sign in to comment.