Skip to content

Commit

Permalink
Fix: Seek to beginning of file when checking if gzip
Browse files Browse the repository at this point in the history
- Plus minor refactor

Signed-off-by: Andrew Meyer <ameyer@pivotal.io>
  • Loading branch information
ameyer-pivotal authored and jromero committed Sep 6, 2019
1 parent ccafced commit ef9b4f2
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 25 deletions.
10 changes: 4 additions & 6 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ import (
"testing"
"time"

"github.com/buildpack/pack/api"
"github.com/buildpack/pack/blob"
"github.com/buildpack/pack/builder"

"github.com/buildpack/pack/style"

dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
Expand All @@ -36,8 +30,12 @@ import (
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpack/pack/api"
"github.com/buildpack/pack/blob"
"github.com/buildpack/pack/builder"
"github.com/buildpack/pack/cache"
"github.com/buildpack/pack/internal/archive"
"github.com/buildpack/pack/style"
h "github.com/buildpack/pack/testhelpers"
)

Expand Down
8 changes: 4 additions & 4 deletions api/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var regex = regexp.MustCompile(`^v?(\d+)\.(\d*)$`)

type Version struct {
major,
minor int64
minor uint64
}

func MustParse(v string) *Version {
Expand All @@ -33,16 +33,16 @@ func NewVersion(v string) (*Version, error) {
}

var (
major, minor int64
major, minor uint64
err error
)
if len(matches[0]) == 3 {
major, err = strconv.ParseInt(matches[0][1], 10, 64)
major, err = strconv.ParseUint(matches[0][1], 10, 64)
if err != nil {
return nil, errors.Wrapf(err, "parsing major %s", style.Symbol(matches[0][1]))
}

minor, err = strconv.ParseInt(matches[0][2], 10, 64)
minor, err = strconv.ParseUint(matches[0][2], 10, 64)
if err != nil {
return nil, errors.Wrapf(err, "parsing minor %s", style.Symbol(matches[0][2]))
}
Expand Down
8 changes: 4 additions & 4 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ func (b blob) Open() (r io.ReadCloser, err error) {

rc := ioutils.NewReadCloserWrapper(gzr, func() error {
defer fh.Close()
if err := gzr.Close(); err != nil {
return err
}
return nil
return gzr.Close()
})

return rc, nil
}

func isGZip(file *os.File) (bool, error) {
b := make([]byte, 3)
if _, err := file.Seek(0, 0); err != nil {
return false, err
}
_, err := file.Read(b)
if err != nil && err != io.EOF {
return false, err
Expand Down
4 changes: 2 additions & 2 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (c *Client) processBuildpacks(buildpacks []string) ([]builder.Buildpack, bu
group := builder.OrderEntry{Group: []builder.BuildpackRef{}}
var bps []builder.Buildpack
for _, bp := range buildpacks {
if isBuildpackId(bp) {
if isBuildpackID(bp) {
id, version := c.parseBuildpack(bp)
group.Group = append(group.Group, builder.BuildpackRef{
BuildpackInfo: builder.BuildpackInfo{
Expand Down Expand Up @@ -246,7 +246,7 @@ func (c *Client) processBuildpacks(buildpacks []string) ([]builder.Buildpack, bu
return bps, group, nil
}

func isBuildpackId(bp string) bool {
func isBuildpackID(bp string) bool {
if !paths.IsURI(bp) {
if _, err := os.Stat(bp); err != nil {
return true
Expand Down
3 changes: 1 addition & 2 deletions build/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"testing"
"time"

"github.com/buildpack/pack/internal/fakes"

"github.com/buildpack/imgutil"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
Expand All @@ -26,6 +24,7 @@ import (
"github.com/buildpack/pack/build"
"github.com/buildpack/pack/builder"
"github.com/buildpack/pack/internal/archive"
"github.com/buildpack/pack/internal/fakes"
"github.com/buildpack/pack/logging"
h "github.com/buildpack/pack/testhelpers"
)
Expand Down
7 changes: 2 additions & 5 deletions commands/inspect_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ import (
"testing"

"github.com/Masterminds/semver"

"github.com/buildpack/pack/api"

"github.com/buildpack/pack/internal/fakes"

"github.com/golang/mock/gomock"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/spf13/cobra"

"github.com/buildpack/pack"
"github.com/buildpack/pack/api"
"github.com/buildpack/pack/builder"
"github.com/buildpack/pack/commands"
cmdmocks "github.com/buildpack/pack/commands/mocks"
"github.com/buildpack/pack/config"
"github.com/buildpack/pack/internal/fakes"
"github.com/buildpack/pack/logging"
h "github.com/buildpack/pack/testhelpers"
)
Expand Down
3 changes: 1 addition & 2 deletions image/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import (
"testing"
"time"

"github.com/buildpack/pack/internal/fakes"

"github.com/docker/docker/client"
"github.com/fatih/color"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpack/pack/image"
"github.com/buildpack/pack/internal/fakes"
h "github.com/buildpack/pack/testhelpers"
)

Expand Down

0 comments on commit ef9b4f2

Please sign in to comment.