diff --git a/go.mod b/go.mod index 39d6d69c07e..421bcc79b49 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/cenkalti/backoff v2.2.1+incompatible github.com/coreos/go-oidc/v3 v3.11.0 github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb - github.com/cs3org/reva/v2 v2.24.2-0.20240917121936-fb394587b472 + github.com/cs3org/reva/v2 v2.24.2-0.20240918135034-5a494dc2ebf7 github.com/dhowden/tag v0.0.0-20230630033851-978a0926ee25 github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e github.com/egirna/icap-client v0.1.1 diff --git a/go.sum b/go.sum index 16994e2c649..453099979f3 100644 --- a/go.sum +++ b/go.sum @@ -255,8 +255,8 @@ github.com/crewjam/saml v0.4.14 h1:g9FBNx62osKusnFzs3QTN5L9CVA/Egfgm+stJShzw/c= github.com/crewjam/saml v0.4.14/go.mod h1:UVSZCf18jJkk6GpWNVqcyQJMD5HsRugBPf4I1nl2mME= github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb h1:KmYZDReplv/yfwc1LNYpDcVhVujC3Pasv6WjXx1haSU= github.com/cs3org/go-cs3apis v0.0.0-20240724121416-062c4e3046cb/go.mod h1:yyP8PRo0EZou3nSH7H4qjlzQwaydPeIRNgX50npQHpE= -github.com/cs3org/reva/v2 v2.24.2-0.20240917121936-fb394587b472 h1:dCgRDvgWefPh6oyqggQ4o7/AcrEAk4niihlX2ZnhGjk= -github.com/cs3org/reva/v2 v2.24.2-0.20240917121936-fb394587b472/go.mod h1:p7CHBXcg6sSqB+0JMNDfC1S7TSh9FghXkw1kTV3KcJI= +github.com/cs3org/reva/v2 v2.24.2-0.20240918135034-5a494dc2ebf7 h1:htjWHMNWh1YLOArxMtjV9zvj9Uu214iyYOHn8wi/10Q= +github.com/cs3org/reva/v2 v2.24.2-0.20240918135034-5a494dc2ebf7/go.mod h1:p7CHBXcg6sSqB+0JMNDfC1S7TSh9FghXkw1kTV3KcJI= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= diff --git a/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/apps.go b/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/apps.go index 2c4bf356c1e..9fd746b2bfe 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/apps.go +++ b/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/apps.go @@ -35,13 +35,13 @@ import ( ) type appsHandler struct { - gatewayClient gateway.GatewayAPIClient - ocmMountPoint string + gatewaySelector *pool.Selector[gateway.GatewayAPIClient] + ocmMountPoint string } func (h *appsHandler) init(c *config) error { var err error - h.gatewayClient, err = pool.GetGatewayServiceClient(c.GatewaySvc) + h.gatewaySelector, err = pool.GatewaySelector(c.GatewaySvc) if err != nil { return err } @@ -99,7 +99,11 @@ func (h *appsHandler) OpenInApp(w http.ResponseWriter, r *http.Request) { } func (h *appsHandler) webappTemplate(ctx context.Context, id *ocmpb.ShareId) (string, error) { - res, err := h.gatewayClient.GetReceivedOCMShare(ctx, &ocmpb.GetReceivedOCMShareRequest{ + gc, err := h.gatewaySelector.Next() + if err != nil { + return "", err + } + res, err := gc.GetReceivedOCMShare(ctx, &ocmpb.GetReceivedOCMShareRequest{ Ref: &ocmpb.ShareReference{ Spec: &ocmpb.ShareReference_Id{ Id: id, diff --git a/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/providers.go b/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/providers.go index 72d8515d4a6..38925081cf3 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/providers.go +++ b/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/providers.go @@ -32,12 +32,12 @@ import ( ) type providersHandler struct { - gatewayClient gateway.GatewayAPIClient + gatewaySelector *pool.Selector[gateway.GatewayAPIClient] } func (h *providersHandler) init(c *config) error { var err error - h.gatewayClient, err = pool.GetGatewayServiceClient(c.GatewaySvc) + h.gatewaySelector, err = pool.GatewaySelector(c.GatewaySvc) if err != nil { return err } @@ -55,7 +55,12 @@ func (h *providersHandler) ListProviders(w http.ResponseWriter, r *http.Request) ctx := r.Context() term := strings.ToLower(r.URL.Query().Get("search")) - listRes, err := h.gatewayClient.ListAllProviders(ctx, &providerpb.ListAllProvidersRequest{}) + gc, err := h.gatewaySelector.Next() + if err != nil { + reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err) + return + } + listRes, err := gc.ListAllProviders(ctx, &providerpb.ListAllProvidersRequest{}) if err != nil { reqres.WriteError(w, r, reqres.APIErrorServerError, "error listing all providers", err) return diff --git a/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/token.go b/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/token.go index 9e42b3d3fbd..007c892d65f 100644 --- a/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/token.go +++ b/vendor/github.com/cs3org/reva/v2/internal/http/services/sciencemesh/token.go @@ -40,7 +40,7 @@ import ( ) type tokenHandler struct { - gatewayClient gateway.GatewayAPIClient + gatewaySelector *pool.Selector[gateway.GatewayAPIClient] meshDirectoryURL string providerDomain string eventStream events.Stream @@ -48,7 +48,7 @@ type tokenHandler struct { func (h *tokenHandler) init(c *config) error { var err error - h.gatewayClient, err = pool.GetGatewayServiceClient(c.GatewaySvc) + h.gatewaySelector, err = pool.GatewaySelector(c.GatewaySvc) if err != nil { return err } @@ -85,7 +85,12 @@ func (h *tokenHandler) Generate(w http.ResponseWriter, r *http.Request) { } ctx := r.Context() - genTokenRes, err := h.gatewayClient.GenerateInviteToken(ctx, &invitepb.GenerateInviteTokenRequest{ + gc, err := h.gatewaySelector.Next() + if err != nil { + reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err) + return + } + genTokenRes, err := gc.GenerateInviteToken(ctx, &invitepb.GenerateInviteTokenRequest{ Description: req.Description, }) switch { @@ -185,7 +190,12 @@ func (h *tokenHandler) AcceptInvite(w http.ResponseWriter, r *http.Request) { return } - providerInfo, err := h.gatewayClient.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{ + gc, err := h.gatewaySelector.Next() + if err != nil { + reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err) + return + } + providerInfo, err := gc.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{ Domain: req.ProviderDomain, }) if err != nil { @@ -197,13 +207,18 @@ func (h *tokenHandler) AcceptInvite(w http.ResponseWriter, r *http.Request) { return } + gc, err = h.gatewaySelector.Next() + if err != nil { + reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err) + return + } forwardInviteReq := &invitepb.ForwardInviteRequest{ InviteToken: &invitepb.InviteToken{ Token: req.Token, }, OriginSystemProvider: providerInfo.ProviderInfo, } - forwardInviteResponse, err := h.gatewayClient.ForwardInvite(ctx, forwardInviteReq) + forwardInviteResponse, err := gc.ForwardInvite(ctx, forwardInviteReq) if err != nil { reqres.WriteError(w, r, reqres.APIErrorServerError, "error sending a grpc forward invite request", err) return @@ -258,7 +273,12 @@ type remoteUser struct { func (h *tokenHandler) FindAccepted(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - res, err := h.gatewayClient.FindAcceptedUsers(ctx, &invitepb.FindAcceptedUsersRequest{}) + gc, err := h.gatewaySelector.Next() + if err != nil { + reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err) + return + } + res, err := gc.FindAcceptedUsers(ctx, &invitepb.FindAcceptedUsersRequest{}) if err != nil { reqres.WriteError(w, r, reqres.APIErrorServerError, "error sending a grpc find accepted users request", err) return @@ -292,7 +312,12 @@ func (h *tokenHandler) DeleteAccepted(w http.ResponseWriter, r *http.Request) { return } - res, err := h.gatewayClient.DeleteAcceptedUser(ctx, &invitepb.DeleteAcceptedUserRequest{ + gc, err := h.gatewaySelector.Next() + if err != nil { + reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err) + return + } + res, err := gc.DeleteAcceptedUser(ctx, &invitepb.DeleteAcceptedUserRequest{ RemoteUserId: &userpb.UserId{ Idp: req.Idp, OpaqueId: req.UserID, @@ -331,7 +356,12 @@ func getDeleteAcceptedRequest(r *http.Request) (*deleteAcceptedRequest, error) { func (h *tokenHandler) ListInvite(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - res, err := h.gatewayClient.ListInviteTokens(ctx, &invitepb.ListInviteTokensRequest{}) + gc, err := h.gatewaySelector.Next() + if err != nil { + reqres.WriteError(w, r, reqres.APIErrorServerError, "error selecting gateway client", err) + return + } + res, err := gc.ListInviteTokens(ctx, &invitepb.ListInviteTokensRequest{}) if err != nil { reqres.WriteError(w, r, reqres.APIErrorServerError, "error listing tokens", err) return diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/session.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/session.go index 1c1386d9b4c..60adc4cf3a1 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/session.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/session.go @@ -26,6 +26,8 @@ import ( "strconv" "time" + "github.com/google/renameio/v2" + "github.com/rogpeppe/go-internal/lockedfile" tusd "github.com/tus/tusd/v2/pkg/handler" userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" @@ -74,7 +76,13 @@ func (s *OcisSession) executantUser() *userpb.User { // Purge deletes the upload session metadata and written binary data func (s *OcisSession) Purge(ctx context.Context) error { - if err := os.Remove(sessionPath(s.store.root, s.info.ID)); err != nil { + sessionPath := sessionPath(s.store.root, s.info.ID) + f, err := lockedfile.OpenFile(sessionPath+".lock", os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0600) + if err != nil { + return err + } + defer f.Close() + if err := os.Remove(sessionPath); err != nil { return err } if err := os.Remove(s.binPath()); err != nil { @@ -93,10 +101,12 @@ func (s *OcisSession) TouchBin() error { } // Persist writes the upload session metadata to disk +// events can update the scan outcome and the finished event might read an empty file because of race conditions +// so we need to lock the file while writing and use atomic writes func (s *OcisSession) Persist(ctx context.Context) error { - uploadPath := sessionPath(s.store.root, s.info.ID) + sessionPath := sessionPath(s.store.root, s.info.ID) // create folder structure (if needed) - if err := os.MkdirAll(filepath.Dir(uploadPath), 0700); err != nil { + if err := os.MkdirAll(filepath.Dir(sessionPath), 0700); err != nil { return err } @@ -105,8 +115,12 @@ func (s *OcisSession) Persist(ctx context.Context) error { if err != nil { return err } - - return os.WriteFile(uploadPath, d, 0600) + f, err := lockedfile.OpenFile(sessionPath+".lock", os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0600) + if err != nil { + return err + } + defer f.Close() + return renameio.WriteFile(sessionPath, d, 0600) } // ToFileInfo returns tus compatible FileInfo so the tus handler can access the upload offset diff --git a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/store.go b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/store.go index 74744e6da9b..1264512205d 100644 --- a/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/store.go +++ b/vendor/github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/upload/store.go @@ -119,7 +119,7 @@ func (store OcisStore) List(ctx context.Context) ([]*OcisSession, error) { // Get returns the upload session for the given upload id func (store OcisStore) Get(ctx context.Context, id string) (*OcisSession, error) { - sessionPath := filepath.Join(store.root, "uploads", id+".info") + sessionPath := sessionPath(store.root, id) match := _idRegexp.FindStringSubmatch(sessionPath) if match == nil || len(match) < 2 { return nil, fmt.Errorf("invalid upload path") @@ -129,6 +129,15 @@ func (store OcisStore) Get(ctx context.Context, id string) (*OcisSession, error) store: store, info: tusd.FileInfo{}, } + lock, err := lockedfile.Open(sessionPath + ".lock") + if err != nil { + if errors.Is(err, iofs.ErrNotExist) { + // Interpret os.ErrNotExist as 404 Not Found + err = tusd.ErrNotFound + } + return nil, err + } + defer lock.Close() data, err := os.ReadFile(sessionPath) if err != nil { if errors.Is(err, iofs.ErrNotExist) { @@ -137,6 +146,8 @@ func (store OcisStore) Get(ctx context.Context, id string) (*OcisSession, error) } return nil, err } + lock.Close() // release lock asap + if err := json.Unmarshal(data, &session.info); err != nil { return nil, err } diff --git a/vendor/modules.txt b/vendor/modules.txt index 6c5a0d5cb5f..ded152a9a95 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -367,7 +367,7 @@ github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1 github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1 github.com/cs3org/go-cs3apis/cs3/tx/v1beta1 github.com/cs3org/go-cs3apis/cs3/types/v1beta1 -# github.com/cs3org/reva/v2 v2.24.2-0.20240917121936-fb394587b472 +# github.com/cs3org/reva/v2 v2.24.2-0.20240918135034-5a494dc2ebf7 ## explicit; go 1.21 github.com/cs3org/reva/v2/cmd/revad/internal/grace github.com/cs3org/reva/v2/cmd/revad/runtime