From 5da4a40ae87fdb2563eb6f9e0192dd4e60eef63e Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Sat, 18 Jul 2020 14:52:44 -0700 Subject: [PATCH] lint: enable more linters Signed-off-by: Tonis Tiigi --- .golangci.yml | 3 +++ cache/manager.go | 13 ++++++------- cache/manager_test.go | 6 +++--- client/llb/meta.go | 2 +- cmd/buildctl/diskusage.go | 2 -- frontend/dockerfile/instructions/bflag_test.go | 6 +++--- frontend/gateway/gateway.go | 2 +- hack/dockerfiles/lint.Dockerfile | 2 +- solver/bboltcachestorage/storage.go | 6 ------ util/pull/pull.go | 8 +------- 10 files changed, 19 insertions(+), 31 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5deaa4846e83..531076814804 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,6 +20,9 @@ linters: - unused - varcheck - golint + - staticcheck + - typecheck + - structcheck disable-all: true issues: diff --git a/cache/manager.go b/cache/manager.go index 3d1e8843607d..6a9a47ea80c9 100644 --- a/cache/manager.go +++ b/cache/manager.go @@ -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 @@ -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() diff --git a/cache/manager_test.go b/cache/manager_test.go index 89ef3f209108..9441de78a164 100644 --- a/cache/manager_test.go +++ b/cache/manager_test.go @@ -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()) @@ -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)) } diff --git a/client/llb/meta.go b/client/llb/meta.go index ab0f59328eb7..a184c48d83aa 100644 --- a/client/llb/meta.go +++ b/client/llb/meta.go @@ -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) diff --git a/cmd/buildctl/diskusage.go b/cmd/buildctl/diskusage.go index 01232fbad23e..33144fa5dde5 100644 --- a/cmd/buildctl/diskusage.go +++ b/cmd/buildctl/diskusage.go @@ -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)) diff --git a/frontend/dockerfile/instructions/bflag_test.go b/frontend/dockerfile/instructions/bflag_test.go index b194ba785f2c..0e880e619066 100644 --- a/frontend/dockerfile/instructions/bflag_test.go +++ b/frontend/dockerfile/instructions/bflag_test.go @@ -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 { @@ -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 { @@ -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 { diff --git a/frontend/gateway/gateway.go b/frontend/gateway/gateway.go index 110c997380bd..dcbc90850443 100644 --- a/frontend/gateway/gateway.go +++ b/frontend/gateway/gateway.go @@ -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 } diff --git a/hack/dockerfiles/lint.Dockerfile b/hack/dockerfiles/lint.Dockerfile index 1f52c39ea436..e6a337af9b15 100644 --- a/hack/dockerfiles/lint.Dockerfile +++ b/hack/dockerfiles/lint.Dockerfile @@ -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 \ No newline at end of file diff --git a/solver/bboltcachestorage/storage.go b/solver/bboltcachestorage/storage.go index 19755816cd5a..515feffbf0d2 100644 --- a/solver/bboltcachestorage/storage.go +++ b/solver/bboltcachestorage/storage.go @@ -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)) } diff --git a/util/pull/pull.go b/util/pull/pull.go index d07434a53802..6684548306fd 100644 --- a/util/pull/pull.go +++ b/util/pull/pull.go @@ -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. @@ -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) @@ -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) }