From 1b7c258ffd48b3fcdaaf30bf3046678a4e6a9926 Mon Sep 17 00:00:00 2001 From: Firas Frikha Date: Tue, 28 Jul 2026 15:44:41 +0200 Subject: [PATCH] chore: bump reva for ocm Delete fix and coordinator PUT groundwork --- go.mod | 2 +- go.sum | 4 +- .../storageprovider/storageprovider.go | 3 +- .../services/dataprovider/dataprovider.go | 3 +- .../reva/v2/pkg/ocm/storage/received/ocm.go | 5 +- .../reva/v2/pkg/upload/coordinated_upload.go | 4 +- .../reva/v2/pkg/upload/coordinator.go | 119 +++++++++++++++--- vendor/modules.txt | 2 +- 8 files changed, 119 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 44756fde052..542d0bf01f1 100644 --- a/go.mod +++ b/go.mod @@ -66,7 +66,7 @@ require ( github.com/open-policy-agent/opa v1.18.2 github.com/orcaman/concurrent-map v1.0.0 github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 - github.com/owncloud/reva/v2 v2.0.0-20260728130639-568de545ed01 + github.com/owncloud/reva/v2 v2.0.0-20260728133518-17c0d7955e2a github.com/pkg/errors v0.9.1 github.com/pkg/xattr v0.4.12 github.com/prometheus/client_golang v1.23.2 diff --git a/go.sum b/go.sum index 09f8e690d36..d204df22a9f 100644 --- a/go.sum +++ b/go.sum @@ -739,8 +739,8 @@ github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HD github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI= github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 h1:JRidLTAKhnvyLMRtVtSF4lhBa0NSAOs6fof+d6JnKII= github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245/go.mod h1:z61VMGAJRtR1nbgXWiNoCkxUXP1B3Je9rMuJbnGd+Og= -github.com/owncloud/reva/v2 v2.0.0-20260728130639-568de545ed01 h1:SHRdsjcYsX3XX5NfAmxcCyn2bZ4IoSvJa6AeTwDP0UE= -github.com/owncloud/reva/v2 v2.0.0-20260728130639-568de545ed01/go.mod h1:m2fGRZDsnNSBszbnwysuq7uhlitQ90+weX4FFQRdkak= +github.com/owncloud/reva/v2 v2.0.0-20260728133518-17c0d7955e2a h1:E7GwsDEP4xke1Fve7ZhWxWQEa6usZg4/r5Q5/i8dEA4= +github.com/owncloud/reva/v2 v2.0.0-20260728133518-17c0d7955e2a/go.mod h1:m2fGRZDsnNSBszbnwysuq7uhlitQ90+weX4FFQRdkak= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c h1:rp5dCmg/yLR3mgFuSOe4oEnDDmGLROTvMragMUXpTQw= github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c/go.mod h1:X07ZCGwUbLaax7L0S3Tw4hpejzu63ZrrQiUe6W0hcy0= github.com/pablodz/inotifywaitgo v0.0.12 h1:DVJJTFMDlSAdO46yisPF2vzozs/r+4k6ih8MVghq78M= diff --git a/vendor/github.com/owncloud/reva/v2/internal/grpc/services/storageprovider/storageprovider.go b/vendor/github.com/owncloud/reva/v2/internal/grpc/services/storageprovider/storageprovider.go index 03fcc381fe6..9ee5e37315c 100644 --- a/vendor/github.com/owncloud/reva/v2/internal/grpc/services/storageprovider/storageprovider.go +++ b/vendor/github.com/owncloud/reva/v2/internal/grpc/services/storageprovider/storageprovider.go @@ -25,6 +25,7 @@ import ( "net/url" "os" "path" + "path/filepath" "sort" "strconv" "strings" @@ -194,7 +195,7 @@ func New(m map[string]interface{}, ss *grpc.Server, log *zerolog.Logger) (rgrpc. if err := store.Setup(); err != nil { return nil, fmt.Errorf("storageprovider: upload directory setup failed: %w", err) } - coordinator := upload.NewCoordinator(fs, store) + coordinator := upload.NewCoordinator(fs, store, filepath.Join(store.Root(), "uploads")) // parse data server url u, err := url.Parse(c.DataServerURL) diff --git a/vendor/github.com/owncloud/reva/v2/internal/http/services/dataprovider/dataprovider.go b/vendor/github.com/owncloud/reva/v2/internal/http/services/dataprovider/dataprovider.go index 9f7f9b74723..f81c0c5fd45 100644 --- a/vendor/github.com/owncloud/reva/v2/internal/http/services/dataprovider/dataprovider.go +++ b/vendor/github.com/owncloud/reva/v2/internal/http/services/dataprovider/dataprovider.go @@ -21,6 +21,7 @@ package dataprovider import ( "fmt" "net/http" + "path/filepath" "github.com/mitchellh/mapstructure" "github.com/rs/zerolog" @@ -115,7 +116,7 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error) if err := store.Setup(); err != nil { return nil, fmt.Errorf("dataprovider: upload directory setup failed: %w", err) } - coord := pkgupload.NewCoordinator(fs, store) + coord := pkgupload.NewCoordinator(fs, store, filepath.Join(store.Root(), "uploads")) dataTXs, err := getDataTXs(conf, coord, fs, evstream, log) if err != nil { diff --git a/vendor/github.com/owncloud/reva/v2/pkg/ocm/storage/received/ocm.go b/vendor/github.com/owncloud/reva/v2/pkg/ocm/storage/received/ocm.go index 641ea2fa12a..cc0612fb014 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/ocm/storage/received/ocm.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/ocm/storage/received/ocm.go @@ -253,7 +253,10 @@ func (d *driver) CreateDir(ctx context.Context, ref *provider.Reference) (*stora } func (d *driver) Delete(ctx context.Context, ref *provider.Reference) (*storage.DeleteResult, error) { - client, _, rel, err := d.webdavClient(ctx, nil, ref) + // The coordinator rolls back a failed upload from the tusd finish path, which + // carries no request auth token, so the share must be resolved as the service + // account on the executant's behalf. + client, _, rel, err := d.serviceWebdavClient(ctx, ref) if err != nil { return nil, err } diff --git a/vendor/github.com/owncloud/reva/v2/pkg/upload/coordinated_upload.go b/vendor/github.com/owncloud/reva/v2/pkg/upload/coordinated_upload.go index e6f9e493459..4765e45e2ca 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/upload/coordinated_upload.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/upload/coordinated_upload.go @@ -68,7 +68,9 @@ func (u *coordinatedUpload) WriteChunk(ctx context.Context, offset int64, src io // recorded at initiate time. Errors are mapped to tusd errors because tusd turns // error types it does not recognise into a bare 500. func (u *coordinatedUpload) FinishUpload(ctx context.Context) error { - err := u.coord.finishUpload(u.session.Context(ctx), u.session) + // tusd reports the result via its own hooks, so the committed resource is + // only of interest to the PUT path. + _, err := u.coord.finishUpload(u.session.Context(ctx), u.session) switch err.(type) { case nil: diff --git a/vendor/github.com/owncloud/reva/v2/pkg/upload/coordinator.go b/vendor/github.com/owncloud/reva/v2/pkg/upload/coordinator.go index 7a0d570f683..b2d1e85e355 100644 --- a/vendor/github.com/owncloud/reva/v2/pkg/upload/coordinator.go +++ b/vendor/github.com/owncloud/reva/v2/pkg/upload/coordinator.go @@ -51,19 +51,30 @@ type Coordinator interface { UseIn(composer *tusd.StoreComposer) // ListUploadSessions returns the upload sessions matching the given filter. ListUploadSessions(ctx context.Context, filter storage.UploadSessionFilter) ([]storage.UploadSession, error) + // Upload writes the whole body of a non-resumable (PUT) upload into the + // session named by req.Ref.Path and finishes it. + Upload(ctx context.Context, req storage.UploadRequest, uff storage.UploadFinishedFunc) (*provider.ResourceInfo, error) } // coordinator is the concrete implementation of Coordinator. type coordinator struct { - fs storage.FS - store SessionStore + fs storage.FS + store SessionStore + chunkHandler *chunking.ChunkHandler } // NewCoordinator constructs a coordinator backed by the given storage driver // and session store. The store must use an on-disk session format the driver's // data path can read (the decomposedfs family: ocis/s3ng/posix). -func NewCoordinator(fs storage.FS, store SessionStore) *coordinator { - return &coordinator{fs: fs, store: store} +// +// chunkFolder stages legacy chunking-v1 parts until the final one arrives; pass +// "" to reject chunked uploads. +func NewCoordinator(fs storage.FS, store SessionStore, chunkFolder string) *coordinator { + c := &coordinator{fs: fs, store: store} + if chunkFolder != "" { + c.chunkHandler = chunking.NewChunkHandler(chunkFolder) + } + return c } // InitiateUpload returns a list of protocols with urls that can be used to append bytes to a new upload session. @@ -334,7 +345,7 @@ func (c *coordinator) initiateUpload(ctx context.Context, ref *provider.Referenc if uploadLength == 0 { // zero-length uploads have no bytes to append, so finish immediately (main: upload.go:333) - if err := c.finishUpload(ctx, session); err != nil { + if _, err := c.finishUpload(ctx, session); err != nil { return nil, err } } @@ -345,20 +356,97 @@ func (c *coordinator) initiateUpload(ctx context.Context, ref *provider.Referenc }, nil } +// Upload writes the entire body of a non-resumable (PUT) upload and finishes it. +// req.Ref.Path carries the session id, as minted by InitiateUpload. +// +// This is the driver-agnostic port of decomposedfs.Upload (upload.go:51). It is +// not yet wired up: the simple and spaces data transfer managers still call +// driver.Upload, because only decomposedfs and ocm implement CommitUpload and +// routing the others here would break their PUT path. +func (c *coordinator) Upload(ctx context.Context, req storage.UploadRequest, uff storage.UploadFinishedFunc) (*provider.ResourceInfo, error) { + session, err := c.store.Get(ctx, req.Ref.GetPath()) + if err != nil { + return nil, err + } + + // The session records the user that initiated the upload; the PUT request + // context may be a different one (or none, behind the data gateway). + ctx = session.Context(ctx) + + if chunk := session.Chunk(); chunk != "" { // legacy chunking v1 + if c.chunkHandler == nil { + return nil, errtypes.NotSupported("coordinator: chunked uploads require a chunk folder") + } + p, assembledFile, err := c.chunkHandler.WriteChunk(chunk, req.Body) + if err != nil { + return nil, err + } + if p == "" { + // Not the final chunk. Each chunk arrives as its own PUT with its own + // session, while the bytes accumulate in the chunk folder, so this + // session has nothing left to hold (main: upload.go:69). + session.Cleanup(true, true) + return nil, errtypes.PartialContent(req.Ref.String()) + } + fd, err := os.Open(assembledFile) + if err != nil { + return nil, err + } + defer fd.Close() + defer os.RemoveAll(assembledFile) + + size, err := session.WriteChunk(ctx, 0, fd) + if err != nil { + return nil, err + } + session.SetSize(size) + } else { + size, err := session.WriteChunk(ctx, 0, req.Body) + if err != nil { + return nil, err + } + if size != req.Length { + return nil, errtypes.PartialContent("coordinator: unexpected end of stream") + } + } + + ri, err := c.finishUpload(ctx, session) + if err != nil { + return nil, err + } + + if uff != nil { + executant := session.Executant() + uff(session.SpaceOwner(), &executant, &provider.Reference{ + ResourceId: &provider.ResourceId{ + StorageId: session.ProviderID(), + SpaceId: session.SpaceID(), + OpaqueId: session.SpaceID(), + }, + Path: utils.MakeRelativePath(filepath.Join(session.Dir(), session.Filename())), + }) + } + + return ri, nil +} + // finishUpload lands a fully-received upload: create the node (new files), verify // checksums, then commit the staged bytes. Zero-length uploads always finish here // synchronously; the async postprocessing path is not ported yet. -func (c *coordinator) finishUpload(ctx context.Context, session Session) error { +// +// Returns the committed resource as the driver reported it, so PUT callers can +// answer with the new etag/mtime/id without recomputing them. +func (c *coordinator) finishUpload(ctx context.Context, session Session) (*provider.ResourceInfo, error) { if err := c.touchAndMark(ctx, session); err != nil { - return err + return nil, err } if err := verifyAndStoreChecksums(ctx, session); err != nil { c.rollback(ctx, session) - return err + return nil, err } if err := session.Persist(ctx); err != nil { c.rollback(ctx, session) - return err + return nil, err } metrics.UploadProcessing.Inc() @@ -407,26 +495,27 @@ func (c *coordinator) touchAndMark(ctx context.Context, session Session) error { } // finishSync commits the staged bytes inline, then unmarks processing and cleans up. -func (c *coordinator) finishSync(ctx context.Context, session Session) error { +func (c *coordinator) finishSync(ctx context.Context, session Session) (*provider.ResourceInfo, error) { ref := session.Reference() f, err := os.Open(session.BinPath()) if err != nil { c.rollback(ctx, session) - return err + return nil, err } - if _, err := c.fs.CommitUpload(ctx, &ref, storage.UploadSource{ + ri, err := c.fs.CommitUpload(ctx, &ref, storage.UploadSource{ Body: f, Length: session.Size(), Metadata: session.Metadata(), Checksums: session.Checksums(), - }); err != nil { + }) + if err != nil { c.rollback(ctx, session) - return err + return nil, err } _ = c.fs.MarkProcessing(ctx, &ref, false, session.ID()) session.Cleanup(true, true) metrics.UploadSessionsFinalized.Inc() - return nil + return ri, nil } // rollback unmarks processing, cleans up session files, and deletes the node if diff --git a/vendor/modules.txt b/vendor/modules.txt index 28f0ef1f8a4..c369d503769 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1321,7 +1321,7 @@ github.com/orcaman/concurrent-map # github.com/owncloud/libre-graph-api-go v1.0.5-0.20260216101009-eeac018af245 ## explicit; go 1.18 github.com/owncloud/libre-graph-api-go -# github.com/owncloud/reva/v2 v2.0.0-20260728130639-568de545ed01 +# github.com/owncloud/reva/v2 v2.0.0-20260728133518-17c0d7955e2a ## explicit; go 1.25.8 github.com/owncloud/reva/v2/cmd/revad/internal/grace github.com/owncloud/reva/v2/cmd/revad/runtime