Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ linters:
- staticcheck
- testifylint
- unused
- unparam
- usestdlibvars
- usetesting
- whitespace
Expand Down Expand Up @@ -93,9 +94,13 @@ linters:
enable-all-rules: false
enable-default-rules: true
rules:
- name: context-as-argument
arguments:
- allow-types-before: "*testing.T"
- name: errorf
- name: if-return
- name: unnecessary-format
- name: unused-parameter
- name: use-errors-new
staticcheck:
checks:
Expand Down Expand Up @@ -126,9 +131,6 @@ linters:
- linters:
- revive
text: superfluous-else
- linters:
- revive
text: unused-parameter
- linters:
- revive
text: redefines-builtin-id
Expand Down
2 changes: 1 addition & 1 deletion cache/blobs_nolinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ import (
"github.com/pkg/errors"
)

func (sr *immutableRef) tryComputeOverlayBlob(_ context.Context, _, _ []mount.Mount, _ string, _ string, _ compression.Compressor) (_ ocispecs.Descriptor, ok bool, err error) {
func (sr *immutableRef) tryComputeOverlayBlob(context.Context, []mount.Mount, []mount.Mount, string, string, compression.Compressor) (_ ocispecs.Descriptor, ok bool, err error) {
return ocispecs.Descriptor{}, true, errors.Errorf("overlayfs-based diff computing is unsupported")
}
8 changes: 4 additions & 4 deletions cache/contenthash/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (cm *cacheManager) Checksum(ctx context.Context, ref cache.ImmutableRef, p
return cc.Checksum(ctx, ref, p, opts, s)
}

func (cm *cacheManager) GetCacheContext(ctx context.Context, md cache.RefMetadata) (CacheContext, error) {
func (cm *cacheManager) GetCacheContext(_ context.Context, md cache.RefMetadata) (CacheContext, error) {
cm.locker.Lock(md.ID())
cm.lruMu.Lock()
v, ok := cm.lru.Get(md.ID())
Expand All @@ -145,7 +145,7 @@ func (cm *cacheManager) GetCacheContext(ctx context.Context, md cache.RefMetadat
return cc, nil
}

func (cm *cacheManager) SetCacheContext(ctx context.Context, md cache.RefMetadata, cci CacheContext) error {
func (cm *cacheManager) SetCacheContext(_ context.Context, md cache.RefMetadata, cci CacheContext) error {
cc, ok := cci.(*cacheContext)
if !ok {
return errors.Errorf("invalid cachecontext: %T", cc)
Expand Down Expand Up @@ -306,13 +306,13 @@ func keyPath(p string) string {
}

// HandleChange notifies the source about a modification operation
func (cc *cacheContext) HandleChange(kind fsutil.ChangeKind, p string, fi os.FileInfo, err error) (retErr error) {
func (cc *cacheContext) HandleChange(kind fsutil.ChangeKind, p string, fi os.FileInfo, _ error) (retErr error) {
p = keyPath(p)
k := convertPathToKey(p)

deleteDir := func(cr *CacheRecord) {
if cr.Type == CacheRecordTypeDir {
cc.node.WalkPrefix(append(k, 0), func(k []byte, v *CacheRecord) bool {
cc.node.WalkPrefix(append(k, 0), func(k []byte, _ *CacheRecord) bool {
cc.txn.Delete(k)
return false
})
Expand Down
3 changes: 2 additions & 1 deletion cache/contenthash/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ func createRef(t *testing.T, cm cache.Manager, files []string) cache.ImmutableRe
return ref
}

//nolint:unparam
func setupCacheManager(t *testing.T, tmpdir string, snapshotterName string, snapshotter snapshots.Snapshotter) (cache.Manager, func()) {
store, err := local.NewStore(tmpdir)
require.NoError(t, err)
Expand Down Expand Up @@ -1612,7 +1613,7 @@ func setupCacheManager(t *testing.T, tmpdir string, snapshotterName string, snap

type badMountable struct{}

func (bm *badMountable) Mount(ctx context.Context, readonly bool, _ session.Group) (snapshot.Mountable, error) {
func (bm *badMountable) Mount(context.Context, bool, session.Group) (snapshot.Mountable, error) {
return nil, errors.New("tried to mount bad mountable")
}

Expand Down
2 changes: 1 addition & 1 deletion cache/contenthash/filehash.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (tsh *tarsumHash) Write(p []byte) (n int, err error) {
return n, err
}

func (tsh *tarsumHash) Sum(_ []byte) []byte {
func (tsh *tarsumHash) Sum([]byte) []byte {
b, _ := hex.DecodeString(tsh.Hash.Sum().Hex())
return b
}
Expand Down
2 changes: 1 addition & 1 deletion cache/contenthash/filehash_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import (
fstypes "github.com/tonistiigi/fsutil/types"
)

func setUnixOpt(_ string, _ os.FileInfo, _ *fstypes.Stat) error {
func setUnixOpt(string, os.FileInfo, *fstypes.Stat) error {
return nil
}
12 changes: 6 additions & 6 deletions cache/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func TestMergeBlobchainID(t *testing.T) {
err = cw.Commit(ctx, 0, cw.Digest())
require.NoError(t, err)
descHandlers[desc.Digest] = &DescHandler{
Provider: func(_ session.Group) content.Provider { return contentBuffer },
Provider: func(session.Group) content.Provider { return contentBuffer },
}
curBlob, err = cm.GetByBlob(ctx, desc, curBlob, descHandlers)
require.NoError(t, err)
Expand Down Expand Up @@ -1217,7 +1217,7 @@ func TestLoopLeaseContent(t *testing.T) {
require.NoError(t, err)
require.NoError(t, cw.Commit(ctx, 0, cw.Digest()))
descHandlers[orgDesc.Digest] = &DescHandler{
Provider: func(_ session.Group) content.Provider { return contentBuffer },
Provider: func(session.Group) content.Provider { return contentBuffer },
}

// Create a compression loop
Expand Down Expand Up @@ -1419,7 +1419,7 @@ func testSharingCompressionVariant(ctx context.Context, t *testing.T, co *cmOut,
require.NoError(t, err)
require.NoError(t, cw.Commit(ctx, 0, cw.Digest()))
descHandlers[aDesc.Digest] = &DescHandler{
Provider: func(_ session.Group) content.Provider { return contentBuffer },
Provider: func(session.Group) content.Provider { return contentBuffer },
}

// Create compression variants
Expand Down Expand Up @@ -1704,7 +1704,7 @@ func TestGetRemotes(t *testing.T) {
require.NoError(t, err)

descHandlers[desc.Digest] = &DescHandler{
Provider: func(_ session.Group) content.Provider { return contentBuffer },
Provider: func(session.Group) content.Provider { return contentBuffer },
}

uncompressedBlobBytes, uncompressedDesc, err := mapToBlob(blobmap, false)
Expand Down Expand Up @@ -2002,7 +2002,7 @@ func TestNondistributableBlobs(t *testing.T) {
require.NoError(t, err)

descHandlers[desc.Digest] = &DescHandler{
Provider: func(_ session.Group) content.Provider { return contentBuffer },
Provider: func(session.Group) content.Provider { return contentBuffer },
}

ref, err := cm.GetByBlob(ctx, desc, nil, descHandlers)
Expand Down Expand Up @@ -2686,7 +2686,7 @@ func zstdBlobDigest(uncompressedBlobBytes []byte) (digest.Digest, error) {

func checkNumBlobs(ctx context.Context, t *testing.T, cs content.Store, expected int) {
c := 0
err := cs.Walk(ctx, func(_ content.Info) error {
err := cs.Walk(ctx, func(content.Info) error {
c++
return nil
})
Expand Down
4 changes: 2 additions & 2 deletions cache/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (md *cacheMetadata) queueDescription(descr string) error {
return md.queueValue(keyDescription, descr, "")
}

//nolint:unparam
func (md *cacheMetadata) queueCommitted(b bool) error {
return md.queueValue(keyCommitted, b, "")
}
Expand Down Expand Up @@ -232,11 +233,10 @@ func (md *cacheMetadata) setEqualMutable(s string) error {
return md.queueValue(keyEqualMutable, s, "")
}

func (md *cacheMetadata) clearEqualMutable() error {
func (md *cacheMetadata) clearEqualMutable() {
md.si.Queue(func(b *bolt.Bucket) error {
return md.si.SetValue(b, keyEqualMutable, nil)
})
return nil
}

func (md *cacheMetadata) queueDiffID(str digest.Digest) error {
Expand Down
2 changes: 1 addition & 1 deletion cache/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,7 @@ func (sr *mutableRef) Mount(ctx context.Context, readonly bool, s session.Group)
return mnt, nil
}

func (sr *mutableRef) Commit(ctx context.Context) (ImmutableRef, error) {
func (sr *mutableRef) Commit(context.Context) (ImmutableRef, error) {
sr.cm.mu.Lock()
defer sr.cm.mu.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion cache/remotecache/azblob/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

// ResolveCacheExporterFunc for "azblob" cache exporter.
func ResolveCacheExporterFunc() remotecache.ResolveCacheExporterFunc {
return func(ctx context.Context, g session.Group, attrs map[string]string) (remotecache.Exporter, error) {
return func(ctx context.Context, _ session.Group, attrs map[string]string) (remotecache.Exporter, error) {
config, err := getConfig(attrs)
if err != nil {
return nil, errors.Wrap(err, "failed to create azblob config")
Expand Down
2 changes: 1 addition & 1 deletion cache/remotecache/azblob/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

// ResolveCacheImporterFunc for "azblob" cache importer.
func ResolveCacheImporterFunc() remotecache.ResolveCacheImporterFunc {
return func(ctx context.Context, g session.Group, attrs map[string]string) (remotecache.Importer, ocispecs.Descriptor, error) {
return func(ctx context.Context, _ session.Group, attrs map[string]string) (remotecache.Importer, ocispecs.Descriptor, error) {
config, err := getConfig(attrs)
if err != nil {
return nil, ocispecs.Descriptor{}, errors.Wrap(err, "failed to create azblob config")
Expand Down
6 changes: 3 additions & 3 deletions cache/remotecache/gha/gha.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func getConfig(conf *ghatypes.CacheConfig, v VerifierProvider, attrs map[string]

// ResolveCacheExporterFunc for Github actions cache exporter.
func ResolveCacheExporterFunc(conf *ghatypes.CacheConfig, v VerifierProvider) remotecache.ResolveCacheExporterFunc {
return func(ctx context.Context, g session.Group, attrs map[string]string) (remotecache.Exporter, error) {
return func(_ context.Context, _ session.Group, attrs map[string]string) (remotecache.Exporter, error) {
cfg, err := getConfig(conf, v, attrs)
if err != nil {
return nil, err
Expand Down Expand Up @@ -313,7 +313,7 @@ func (ce *exporter) Finalize(ctx context.Context) (_ map[string]string, err erro
return nil, err
}

if err := ce.cache.SaveMutable(ctx, ce.indexKey(), 15*time.Second, func(old *actionscache.Entry) (actionscache.Blob, error) {
if err := ce.cache.SaveMutable(ctx, ce.indexKey(), 15*time.Second, func(*actionscache.Entry) (actionscache.Blob, error) {
return actionscache.NewBlob(dt), nil
}); err != nil {
return nil, err
Expand Down Expand Up @@ -422,7 +422,7 @@ func certToStringMap(cert *certificate.Summary) (map[string]string, error) {

// ResolveCacheImporterFunc for Github actions cache importer.
func ResolveCacheImporterFunc(conf *ghatypes.CacheConfig, v VerifierProvider) remotecache.ResolveCacheImporterFunc {
return func(ctx context.Context, g session.Group, attrs map[string]string) (remotecache.Importer, ocispecs.Descriptor, error) {
return func(_ context.Context, _ session.Group, attrs map[string]string) (remotecache.Importer, ocispecs.Descriptor, error) {
cfg, err := getConfig(conf, v, attrs)
if err != nil {
return nil, ocispecs.Descriptor{}, err
Expand Down
4 changes: 2 additions & 2 deletions cache/remotecache/inline/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func ResolveCacheExporterFunc() remotecache.ResolveCacheExporterFunc {
return func(ctx context.Context, _ session.Group, _ map[string]string) (remotecache.Exporter, error) {
return func(context.Context, session.Group, map[string]string) (remotecache.Exporter, error) {
return NewExporter(), nil
}
}
Expand All @@ -43,7 +43,7 @@ func (ce *exporter) Config() remotecache.Config {
}
}

func (ce *exporter) Finalize(ctx context.Context) (map[string]string, error) {
func (ce *exporter) Finalize(context.Context) (map[string]string, error) {
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cache/remotecache/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ type unlazyProvider struct {
s session.Group
}

func (p *unlazyProvider) UnlazySession(desc ocispecs.Descriptor) session.Group {
func (p *unlazyProvider) UnlazySession(ocispecs.Descriptor) session.Group {
return p.s
}
2 changes: 1 addition & 1 deletion cache/remotecache/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func getConfig(attrs map[string]string) (Config, error) {

// ResolveCacheExporterFunc for s3 cache exporter.
func ResolveCacheExporterFunc() remotecache.ResolveCacheExporterFunc {
return func(ctx context.Context, g session.Group, attrs map[string]string) (remotecache.Exporter, error) {
return func(ctx context.Context, _ session.Group, attrs map[string]string) (remotecache.Exporter, error) {
config, err := getConfig(attrs)
if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions cache/remotecache/v1/cachestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ func (cs *cacheKeyStorage) Load(id string, resultID string) (solver.CacheResult,
return res, nil
}

func (cs *cacheKeyStorage) AddResult(id string, res solver.CacheResult) error {
func (cs *cacheKeyStorage) AddResult(string, solver.CacheResult) error {
return nil
}

func (cs *cacheKeyStorage) Release(resultID string) error {
func (cs *cacheKeyStorage) Release(string) error {
return nil
}
func (cs *cacheKeyStorage) AddLink(id string, link solver.CacheInfoLink, target string) error {
func (cs *cacheKeyStorage) AddLink(string, solver.CacheInfoLink, string) error {
return nil
}

Expand Down Expand Up @@ -255,7 +255,7 @@ type cacheResultStorage struct {
byItem map[*item]string
}

func (cs *cacheResultStorage) Save(res solver.Result, createdAt time.Time) (solver.CacheResult, error) {
func (cs *cacheResultStorage) Save(solver.Result, time.Time) (solver.CacheResult, error) {
return solver.CacheResult{}, errors.New("importer is immutable")
}

Expand Down Expand Up @@ -323,7 +323,7 @@ func (cs *cacheResultStorage) Load(ctx context.Context, res solver.CacheResult)
return nil, errors.WithStack(solver.ErrNotFound)
}

func (cs *cacheResultStorage) LoadRemotes(ctx context.Context, res solver.CacheResult, compressionopts *compression.Config, _ session.Group) ([]*solver.Remote, error) {
func (cs *cacheResultStorage) LoadRemotes(_ context.Context, res solver.CacheResult, compressionopts *compression.Config, _ session.Group) ([]*solver.Remote, error) {
if it := cs.byResultID(res.ID); it != nil {
for _, r := range it.results {
if compressionopts == nil {
Expand Down Expand Up @@ -352,7 +352,7 @@ func (cs *cacheResultStorage) LoadRemotes(ctx context.Context, res solver.CacheR
return nil, errors.WithStack(solver.ErrNotFound)
}

func (cs *cacheResultStorage) Exists(ctx context.Context, id string) bool {
func (cs *cacheResultStorage) Exists(_ context.Context, id string) bool {
return cs.byResultID(id) != nil
}

Expand Down
6 changes: 3 additions & 3 deletions cache/util/fsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type FileRange struct {
Length int
}

func ReadFile(ctx context.Context, root string, req ReadRequest) ([]byte, error) {
func ReadFile(_ context.Context, root string, req ReadRequest) ([]byte, error) {
fp, err := fs.RootPath(root, req.Filename)
if err != nil {
return nil, errors.WithStack(err)
Expand Down Expand Up @@ -77,7 +77,7 @@ func ReadDir(ctx context.Context, root string, req ReadDirRequest) ([]*fstypes.S
if err != nil {
return nil, errors.WithStack(err)
}
err = fsutil.Walk(ctx, fp, &fo, func(path string, info os.FileInfo, err error) error {
err = fsutil.Walk(ctx, fp, &fo, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return errors.Wrapf(err, "walking %q", root)
}
Expand All @@ -99,7 +99,7 @@ func ReadDir(ctx context.Context, root string, req ReadDirRequest) ([]*fstypes.S
return rd, nil
}

func StatFile(ctx context.Context, root string, path string) (*fstypes.Stat, error) {
func StatFile(_ context.Context, root string, path string) (*fstypes.Stat, error) {
fp, err := fs.RootPath(root, path)
if err != nil {
return nil, errors.WithStack(err)
Expand Down
2 changes: 1 addition & 1 deletion client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (g *gatewayClientForBuild) ExecProcess(ctx context.Context, opts ...grpc.Ca
return g.gateway.ExecProcess(ctx, opts...)
}

func (g *gatewayClientForBuild) Warn(ctx context.Context, in *gatewayapi.WarnRequest, opts ...grpc.CallOption) (*gatewayapi.WarnResponse, error) {
func (g *gatewayClientForBuild) Warn(ctx context.Context, in *gatewayapi.WarnRequest, _ ...grpc.CallOption) (*gatewayapi.WarnResponse, error) {
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
return g.gateway.Warn(ctx, in)
}
2 changes: 1 addition & 1 deletion client/client_export_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ func testOCIExporterContentStore(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

checkStore := func(dir string) {
err = filepath.Walk(dir, func(filename string, fi os.FileInfo, err error) error {
err = filepath.Walk(dir, func(filename string, fi os.FileInfo, _ error) error {
filename = strings.TrimPrefix(filename, dir)
filename = strings.Trim(filename, "/")
if filename == "" || filename == "ingest" {
Expand Down
4 changes: 2 additions & 2 deletions client/client_export_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ func testSessionExporter(t *testing.T, sb integration.Sandbox) {
exporterCalled := false
// The provider has no finalization callback; FinalizeExport returning
// Unimplemented must not fail the solve.
exporter := exporterprovider.New(func(ctx context.Context, md map[string][]byte, refs []string) ([]*exporter.ExporterRequest, error) {
exporter := exporterprovider.New(func(_ context.Context, _ map[string][]byte, refs []string) ([]*exporter.ExporterRequest, error) {
require.Len(t, refs, 1)
g := c.GatewayClientForBuild(buildID)
resp, err := g.ReadDir(sb.Context(), &gatewaypb.ReadDirRequest{
Expand Down Expand Up @@ -833,7 +833,7 @@ func testTarExporterWithSocket(t *testing.T, sb integration.Sandbox) {
{
Type: ExporterTar,
Attrs: map[string]string{},
Output: func(m map[string]string) (io.WriteCloser, error) {
Output: func(map[string]string) (io.WriteCloser, error) {
return &iohelper.NopWriteCloser{Writer: io.Discard}, nil
},
},
Expand Down
Loading