Skip to content

Commit

Permalink
lint: enable more linters
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Jul 19, 2020
1 parent dc40e57 commit 5da4a40
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ linters:
- unused
- varcheck
- golint
- staticcheck
- typecheck
- structcheck
disable-all: true

issues:
Expand Down
13 changes: 6 additions & 7 deletions cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispec.Descriptor,
return nil, err
}

for _, si := range sis {
ref, err := cm.get(ctx, si.ID(), opts...)
if len(sis) > 0 {
ref, err := cm.get(ctx, sis[0].ID(), opts...)
if err != nil && !IsNotFound(err) {
return nil, errors.Wrapf(err, "failed to get record %s by blobchainid", si.ID())
return nil, errors.Wrapf(err, "failed to get record %s by blobchainid", sis[0].ID())
}
if p != nil {
releaseParent = true
Expand All @@ -158,13 +158,12 @@ func (cm *cacheManager) GetByBlob(ctx context.Context, desc ocispec.Descriptor,
}

var link ImmutableRef
for _, si := range sis {
ref, err := cm.get(ctx, si.ID(), opts...)
if len(sis) > 0 {
ref, err := cm.get(ctx, sis[0].ID(), opts...)
if err != nil && !IsNotFound(err) {
return nil, errors.Wrapf(err, "failed to get record %s by chainid", si.ID())
return nil, errors.Wrapf(err, "failed to get record %s by chainid", sis[0].ID())
}
link = ref
break
}

id := identity.NewID()
Expand Down
6 changes: 3 additions & 3 deletions cache/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,13 @@ func TestExtractOnMutable(t *testing.T) {
err = content.WriteBlob(ctx, co.cs, "ref2", bytes.NewBuffer(b2), desc2)
require.NoError(t, err)

snap2, err := cm.GetByBlob(ctx, desc2, snap)
_, err = cm.GetByBlob(ctx, desc2, snap)
require.Error(t, err)

err = snap.SetBlob(ctx, desc)
require.NoError(t, err)

snap2, err = cm.GetByBlob(ctx, desc2, snap)
snap2, err := cm.GetByBlob(ctx, desc2, snap)
require.NoError(t, err)

err = snap.Release(context.TODO())
Expand Down Expand Up @@ -930,7 +930,7 @@ func TestLazyCommit(t *testing.T) {
err = snap2.Release(ctx)
require.NoError(t, err)

active, err = cm.GetMutable(ctx, active.ID())
_, err = cm.GetMutable(ctx, active.ID())
require.Error(t, err)
require.Equal(t, true, errors.Is(err, errNotFound))
}
Expand Down
2 changes: 1 addition & 1 deletion client/llb/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func shlexf(str string, replace bool, v ...interface{}) StateOption {
}
return func(s State) State {
arg, err := shlex.Split(str)
if err != nil {
if err != nil { //nolint
// TODO: handle error
}
return args(arg...)(s)
Expand Down
2 changes: 0 additions & 2 deletions cmd/buildctl/diskusage.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ func printSummary(tw *tabwriter.Writer, du []*client.UsageInfo) {
}
}

tw = tabwriter.NewWriter(os.Stdout, 1, 8, 1, '\t', 0)

if shared > 0 {
fmt.Fprintf(tw, "Shared:\t%.2f\n", units.Bytes(shared))
fmt.Fprintf(tw, "Private:\t%.2f\n", units.Bytes(total-shared))
Expand Down
6 changes: 3 additions & 3 deletions frontend/dockerfile/instructions/bflag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestBuilderFlags(t *testing.T) {
// ---

bf = NewBFlags()
flStr1 = bf.AddString("str1", "HI")
bf.AddString("str1", "HI")
bf.Args = []string{"--str1"}

if err = bf.Parse(); err == nil {
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestBuilderFlags(t *testing.T) {
// ---

bf = NewBFlags()
flBool1 = bf.AddBool("bool1", false)
bf.AddBool("bool1", false)
bf.Args = []string{"--bool1=false1"}

if err = bf.Parse(); err == nil {
Expand All @@ -160,7 +160,7 @@ func TestBuilderFlags(t *testing.T) {
// ---

bf = NewBFlags()
flBool1 = bf.AddBool("bool1", false)
bf.AddBool("bool1", false)
bf.Args = []string{"--bool2"}

if err = bf.Parse(); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion frontend/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (gf *gatewayFrontend) Solve(ctx context.Context, llbBridge frontend.Fronten
}

lbf, ctx, err := serveLLBBridgeForwarder(ctx, llbBridge, gf.workers, inputs, sid)
defer lbf.conn.Close()
defer lbf.conn.Close() //nolint
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion hack/dockerfiles/lint.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ FROM golang:1.13-alpine
RUN apk add --no-cache gcc musl-dev
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.27.0
WORKDIR /go/src/github.com/moby/buildkit
RUN --mount=target=/go/src/github.com/moby/buildkit \
RUN --mount=target=/go/src/github.com/moby/buildkit --mount=target=/root/.cache,type=cache \
golangci-lint run
6 changes: 0 additions & 6 deletions solver/bboltcachestorage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,6 @@ func (s *Store) releaseHelper(tx *bolt.Tx, id, resultID string) error {
}
}

links := tx.Bucket([]byte(resultBucket))
if results == nil {
return nil
}
links = links.Bucket([]byte(id))

return s.emptyBranchWithParents(tx, []byte(id))
}

Expand Down
8 changes: 1 addition & 7 deletions util/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (p *Puller) Pull(ctx context.Context) (*Pulled, error) {
}
stopProgress()

var usedBlobs, unusedBlobs []ocispec.Descriptor
var usedBlobs []ocispec.Descriptor

if schema1Converter != nil {
ongoing.remove(p.desc) // Not left in the content store so this is sufficient.
Expand Down Expand Up @@ -174,10 +174,6 @@ func (p *Puller) Pull(ctx context.Context) (*Pulled, error) {
if err := images.Dispatch(ctx, images.Handlers(handlers...), nil, p.desc); err != nil {
return nil, err
}

for _, j := range allBlobs {
unusedBlobs = append(unusedBlobs, j)
}
} else {
for _, j := range ongoing.added {
usedBlobs = append(usedBlobs, j.Descriptor)
Expand All @@ -186,11 +182,9 @@ func (p *Puller) Pull(ctx context.Context) (*Pulled, error) {

// split all pulled data to layers and rest. layers remain roots and are deleted with snapshots. rest will be linked to layers.
var notLayerBlobs []ocispec.Descriptor
var layerBlobs []ocispec.Descriptor
for _, j := range usedBlobs {
switch j.MediaType {
case ocispec.MediaTypeImageLayer, images.MediaTypeDockerSchema2Layer, ocispec.MediaTypeImageLayerGzip, images.MediaTypeDockerSchema2LayerGzip, images.MediaTypeDockerSchema2LayerForeign, images.MediaTypeDockerSchema2LayerForeignGzip:
layerBlobs = append(layerBlobs, j)
default:
notLayerBlobs = append(notLayerBlobs, j)
}
Expand Down

0 comments on commit 5da4a40

Please sign in to comment.