Skip to content

Commit

Permalink
bump golangci-lint to 1.61.0
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Oct 17, 2024
1 parent e5baacc commit e7d8640
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ linters:
- revive
- goimports
- unconvert
- exportloopref
- copyloopvar
- misspell
- gocritic
- prealloc
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ toolchain-clean:

$(GOLANGCI_LINT):
@mkdir -p $(@D)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINDIR=$(@D) sh -s v1.55.2
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | BINDIR=$(@D) sh -s v1.61.0

.PHONY: check-changelog
lint: $(GOLANGCI_LINT)
Expand Down
3 changes: 3 additions & 0 deletions changelog/unreleased/bump-golangci-lint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Bump golangci-lint to 1.61.0

https://github.com/cs3org/reva/pull/4890
30 changes: 14 additions & 16 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ func (s *Service) Delete(ctx context.Context, req *provider.DeleteRequest) (*pro
if req.Opaque != nil {
if _, ok := req.Opaque.Map["deleting_shared_resource"]; ok {
// it is a binary key; its existence signals true. Although, do not assume.
ctx = context.WithValue(ctx, appctx.DeletingSharedResource, true)
ctx = appctx.WithDeletingSharedResource(ctx)
}
}

Expand Down Expand Up @@ -1095,20 +1095,24 @@ func (s *Service) DenyGrant(ctx context.Context, req *provider.DenyGrantRequest)
return res, nil
}

type spaceTypeKey struct{}

func WithSpaceType(ctx context.Context, spaceType string) context.Context {
return context.WithValue(ctx, spaceTypeKey{}, spaceType)
}
func SpaceTypeFromContext(ctx context.Context) (string, bool) {
spaceType, ok := ctx.Value(spaceTypeKey{}).(string)
return spaceType, ok
}

func (s *Service) AddGrant(ctx context.Context, req *provider.AddGrantRequest) (*provider.AddGrantResponse, error) {
ctx = ctxpkg.ContextSetLockID(ctx, req.LockId)

// TODO: update CS3 APIs
// FIXME these should be part of the AddGrantRequest object
// https://github.com/owncloud/ocis/issues/4312
if utils.ExistsInOpaque(req.Opaque, "spacegrant") {
ctx = context.WithValue(
ctx,
utils.SpaceGrant,
struct{ SpaceType string }{
SpaceType: utils.ReadPlainFromOpaque(req.Opaque, "spacetype"),
},
)
ctx = WithSpaceType(ctx, utils.ReadPlainFromOpaque(req.Opaque, "spacetype"))
}

// check grantee type is valid
Expand Down Expand Up @@ -1137,13 +1141,7 @@ func (s *Service) UpdateGrant(ctx context.Context, req *provider.UpdateGrantRequ
// FIXME these should be part of the AddGrantRequest object
// https://github.com/owncloud/ocis/issues/4312
if utils.ExistsInOpaque(req.Opaque, "spacegrant") {
ctx = context.WithValue(
ctx,
utils.SpaceGrant,
struct{ SpaceType string }{
SpaceType: utils.ReadPlainFromOpaque(req.Opaque, "spacetype"),
},
)
ctx = WithSpaceType(ctx, utils.ReadPlainFromOpaque(req.Opaque, "spacetype"))
}

// check grantee type is valid
Expand Down Expand Up @@ -1174,7 +1172,7 @@ func (s *Service) RemoveGrant(ctx context.Context, req *provider.RemoveGrantRequ
// FIXME these should be part of the RemoveGrantRequest object
// https://github.com/owncloud/ocis/issues/4312
if utils.ExistsInOpaque(req.Opaque, "spacegrant") {
ctx = context.WithValue(ctx, utils.SpaceGrant, struct{}{})
ctx = WithSpaceType(ctx, "")
}

err := s.Storage.RemoveGrant(ctx, req.Ref, req.Grant)
Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocdav/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,6 @@ func NewErrFromStatus(s *rpc.Status) error {
case rpc.Code_CODE_UNIMPLEMENTED:
return ErrNotImplemented
default:
return fmt.Errorf(s.GetMessage())
return fmt.Errorf("%s", s.GetMessage())
}
}
4 changes: 2 additions & 2 deletions internal/http/services/owncloud/ocdav/mkcol.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ func (s *svc) handleMkcol(ctx context.Context, w http.ResponseWriter, r *http.Re
}
return http.StatusForbidden, errors.New(sRes.Status.Message)
case res.Status.Code == rpc.Code_CODE_ABORTED:
return http.StatusPreconditionFailed, fmt.Errorf(res.Status.Message)
return http.StatusPreconditionFailed, fmt.Errorf("%s", res.Status.Message)
case res.Status.Code == rpc.Code_CODE_FAILED_PRECONDITION:
// https://www.rfc-editor.org/rfc/rfc4918#section-9.3.1:
// 409 (Conflict) - A collection cannot be made at the Request-URI until
// one or more intermediate collections have been created. The server
// MUST NOT create those intermediate collections automatically.
return http.StatusConflict, fmt.Errorf(res.Status.Message)
return http.StatusConflict, fmt.Errorf("%s", res.Status.Message)
case res.Status.Code == rpc.Code_CODE_ALREADY_EXISTS:
// https://www.rfc-editor.org/rfc/rfc4918#section-9.3.1:
// 405 (Method Not Allowed) - MKCOL can only be executed on an unmapped URL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func getSharedResource(ctx context.Context, client gateway.GatewayAPIClient, res
e := fmt.Errorf("not found")
return nil, arbitraryOcsResponse(response.MetaNotFound.StatusCode, e.Error())
}
e := fmt.Errorf(res.GetStatus().GetMessage())
e := fmt.Errorf("%s", res.GetStatus().GetMessage())
return nil, arbitraryOcsResponse(response.MetaServerError.StatusCode, e.Error())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,6 @@ var _ = Describe("The ocs API", func() {

Context("when change the permission", func() {
for _, perm := range []string{"4", "5", "15"} {
perm := perm
It("the password exists. update succeed", func() {
form := url.Values{}
form.Add("permissions", perm)
Expand Down
11 changes: 9 additions & 2 deletions pkg/appctx/appctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ import (
"go.opentelemetry.io/otel/trace"
)

// DeletingSharedResource flags to a storage a shared resource is being deleted not by the owner.
var DeletingSharedResource struct{}
// dletingSharedResource flags to a storage a shared resource is being deleted not by the owner.
type deletingSharedResource struct{}

func WithDeletingSharedResource(ctx context.Context) context.Context {
return context.WithValue(ctx, deletingSharedResource{}, struct{}{})
}
func DeletingSharedResourceFromContext(ctx context.Context) bool {
return ctx.Value(deletingSharedResource{}) == nil
}

// WithLogger returns a context with an associated logger.
func WithLogger(ctx context.Context, l *zerolog.Logger) context.Context {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mentix/exchangers/importers/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (importer *BaseImporter) Process(connectors *connectors.Collection) (bool,

var err error
if len(processErrs) != 0 {
err = fmt.Errorf(strings.Join(processErrs, "; "))
err = fmt.Errorf("%s", strings.Join(processErrs, "; "))
}
return true, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/ocm/share/repository/nextcloud/nextcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"fmt"
"io"
"net/http"
"strconv"
"strings"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
Expand Down Expand Up @@ -431,7 +430,7 @@ func (sm *Manager) do(ctx context.Context, a Action, username string) (int, []by
log.Info().Msgf("am.do response %d %s", resp.StatusCode, body)

if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated {
return 0, nil, fmt.Errorf("Unexpected response code from EFSS API: " + strconv.Itoa(resp.StatusCode))
return 0, nil, fmt.Errorf("Unexpected response code from EFSS API: %d", resp.StatusCode)
}
return resp.StatusCode, body, nil
}
4 changes: 1 addition & 3 deletions pkg/storage/fs/posix/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,7 @@ func (t *Tree) Delete(ctx context.Context, n *node.Node) error {
// remove entry from cache immediately to avoid inconsistencies
defer func() { _ = t.idCache.Delete(path) }()

deletingSharedResource := ctx.Value(appctx.DeletingSharedResource)

if deletingSharedResource != nil && deletingSharedResource.(bool) {
if appctx.DeletingSharedResourceFromContext(ctx) {
src := filepath.Join(n.ParentPath(), n.Name)
return os.RemoveAll(src)
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/storage/utils/decomposedfs/grants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strings"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/v2/internal/grpc/services/storageprovider"
"github.com/cs3org/reva/v2/pkg/appctx"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/errtypes"
Expand Down Expand Up @@ -227,7 +228,8 @@ func (fs *Decomposedfs) RemoveGrant(ctx context.Context, ref *provider.Reference
}

func isShareGrant(ctx context.Context) bool {
return ctx.Value(utils.SpaceGrant) == nil
_, ok := storageprovider.SpaceTypeFromContext(ctx)
return !ok
}

// UpdateGrant updates a grant on a resource
Expand Down Expand Up @@ -306,16 +308,12 @@ func (fs *Decomposedfs) loadGrant(ctx context.Context, ref *provider.Reference,
}

func (fs *Decomposedfs) storeGrant(ctx context.Context, n *node.Node, g *provider.Grant) error {
var spaceType string
spaceGrant := ctx.Value(utils.SpaceGrant)
// this is not a grant on a space root we are just adding a share
if spaceGrant == nil {
// if is a grant to a space root, the receiver needs the space type to update the indexes
spaceType, ok := storageprovider.SpaceTypeFromContext(ctx)
if !ok {
// this is not a grant on a space root we are just adding a share
spaceType = spaceTypeShare
}
// this is a grant to a space root, the receiver needs the space type to update the indexes
if sg, ok := spaceGrant.(struct{ SpaceType string }); ok && sg.SpaceType != "" {
spaceType = sg.SpaceType
}

// set the grant
e := ace.FromGrant(g)
Expand Down
5 changes: 3 additions & 2 deletions pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
v1beta11 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/v2/internal/grpc/services/storageprovider"
"github.com/cs3org/reva/v2/pkg/appctx"
ocsconv "github.com/cs3org/reva/v2/pkg/conversions"
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
Expand Down Expand Up @@ -65,7 +66,7 @@ const (

// CreateStorageSpace creates a storage space
func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.CreateStorageSpaceRequest) (*provider.CreateStorageSpaceResponse, error) {
ctx = context.WithValue(ctx, utils.SpaceGrant, struct{}{})
ctx = storageprovider.WithSpaceType(ctx, "")
u := ctxpkg.ContextMustGetUser(ctx)

// "everything is a resource" this is the unique ID for the Space resource.
Expand Down Expand Up @@ -195,7 +196,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
return nil, err
}

ctx = context.WithValue(ctx, utils.SpaceGrant, struct{ SpaceType string }{SpaceType: req.Type})
ctx = storageprovider.WithSpaceType(ctx, req.Type)

if req.Type != _spaceTypePersonal {
if err := fs.AddGrant(ctx, &provider.Reference{
Expand Down
4 changes: 1 addition & 3 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ func (t *Tree) Delete(ctx context.Context, n *node.Node) (err error) {
// remove entry from cache immediately to avoid inconsistencies
defer func() { _ = t.idCache.Delete(path) }()

deletingSharedResource := ctx.Value(appctx.DeletingSharedResource)

if deletingSharedResource != nil && deletingSharedResource.(bool) {
if appctx.DeletingSharedResourceFromContext(ctx) {
src := filepath.Join(n.ParentPath(), n.Name)
return os.Remove(src)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/utils/decomposedfs/upload/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func TestInitNewNode(t *testing.T) {

err := os.MkdirAll(rootNode.InternalPath(), 0700)
if err != nil {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
n := node.New("e48c4e7a-beac-4b82-b991-a5cff7b8c39c", "930b7a2e-b745-41e1-8a9b-712582021842", "e48c4e7a-beac-4b82-b991-a5cff7b8c39c", "newchild", 10, "26493c53-2634-45f8-949f-dc07b88df9b0", providerv1beta1.ResourceType_RESOURCE_TYPE_FILE, &userv1beta1.UserId{}, lookup)
n.SpaceRoot = rootNode
unlock, err := store.tp.InitNewNode(context.Background(), n, 10)
if err != nil {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
defer func() {
_ = unlock()
Expand Down
2 changes: 1 addition & 1 deletion pkg/user/manager/ldap/ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ func TestUserManager(t *testing.T) {
// positive tests for New
_, err = New(map[string]interface{}{})
if err != nil {
t.Fatalf(err.Error())
t.Fatal(err.Error())
}
}
1 change: 0 additions & 1 deletion pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var skipTests = []struct {

func TestSkip(t *testing.T) {
for _, tt := range skipTests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
r := Skip(tt.url, tt.base)
if r != tt.out {
Expand Down

0 comments on commit e7d8640

Please sign in to comment.