diff --git a/internal/grpc/services/storageprovider/storageprovider.go b/internal/grpc/services/storageprovider/storageprovider.go index d87b5d81c9c..bad19304f1d 100644 --- a/internal/grpc/services/storageprovider/storageprovider.go +++ b/internal/grpc/services/storageprovider/storageprovider.go @@ -453,8 +453,6 @@ func (s *service) InitiateFileUpload(ctx context.Context, req *provider.Initiate }, nil } - // extract all metadata from (custom) headers - // TODO(lopresti) They are defined in the http/services/ownclod/ocdav package (webdav.go) but duplicated here metadata := map[string]string{} var uploadLength int64 if req.Opaque != nil && req.Opaque.Map != nil { @@ -475,13 +473,6 @@ func (s *service) InitiateFileUpload(ctx context.Context, req *provider.Initiate if req.Opaque.Map["X-OC-Mtime"] != nil { metadata["mtime"] = string(req.Opaque.Map["X-OC-Mtime"].Value) } - // in addition to the lock_id we may have the lock holder - if req.Opaque.Map["Lock-Holder"] != nil { - metadata["lockholder"] = string(req.Opaque.Map["Lock-Holder"].Value) - } - } - if req.LockId != "" { - metadata["lockid"] = req.LockId } uploadIDs, err := s.storage.InitiateUpload(ctx, newRef, uploadLength, metadata) if err != nil { diff --git a/internal/http/services/owncloud/ocdav/put.go b/internal/http/services/owncloud/ocdav/put.go index 75f97fb4d16..e9a000b1bf4 100644 --- a/internal/http/services/owncloud/ocdav/put.go +++ b/internal/http/services/owncloud/ocdav/put.go @@ -186,13 +186,6 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ w.Header().Set(HeaderOCMtime, "accepted") } - if lockholder := r.Header.Get(HeaderLockHolder); lockholder != "" { - opaqueMap[HeaderLockHolder] = &typespb.OpaqueEntry{ - Decoder: "plain", - Value: []byte(lockholder), - } - } - // curl -X PUT https://demo.owncloud.com/remote.php/webdav/testcs.bin -u demo:demo -d '123' -v -H 'OC-Checksum: SHA1:40bd001563085fc35165329ea1ff5c5ecbdbbeef' var cparts []string @@ -278,6 +271,12 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ return } httpReq.Header.Set(datagateway.TokenTransportHeader, token) + if lockid := r.Header.Get(HeaderLockID); lockid != "" { + httpReq.Header.Set(HeaderLockID, lockid) + } + if lockholder := r.Header.Get(HeaderLockHolder); lockholder != "" { + httpReq.Header.Set(HeaderLockHolder, lockholder) + } httpRes, err := s.client.Do(httpReq) if err != nil { diff --git a/internal/http/services/owncloud/ocdav/webdav.go b/internal/http/services/owncloud/ocdav/webdav.go index c2e2d58fd53..06a1480156c 100644 --- a/internal/http/services/owncloud/ocdav/webdav.go +++ b/internal/http/services/owncloud/ocdav/webdav.go @@ -76,7 +76,8 @@ const ( HeaderOCMtime = "X-OC-Mtime" HeaderExpectedEntityLength = "X-Expected-Entity-Length" HeaderTransferAuth = "TransferHeaderAuthorization" - HeaderLockHolder = "Lock-Holder" + HeaderLockID = "X-Lock-Id" + HeaderLockHolder = "X-Lock-Holder" ) // WebDavHandler implements a dav endpoint. diff --git a/pkg/ocm/storage/outcoming/ocm.go b/pkg/ocm/storage/outcoming/ocm.go index 337050c3407..608ccea2117 100644 --- a/pkg/ocm/storage/outcoming/ocm.go +++ b/pkg/ocm/storage/outcoming/ocm.go @@ -34,6 +34,7 @@ import ( provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typespb "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" "github.com/cs3org/reva/internal/http/services/datagateway" + "github.com/cs3org/reva/internal/http/services/owncloud/ocdav" "github.com/cs3org/reva/internal/http/services/owncloud/ocs/conversions" "github.com/cs3org/reva/pkg/appctx" @@ -399,20 +400,9 @@ func (d *driver) Upload(ctx context.Context, ref *provider.Reference, content io } return d.unwrappedOpFromShareCreator(ctx, share, rel, func(ctx context.Context, newRef *provider.Reference) error { - opaqueMap := map[string]*typespb.OpaqueEntry{} - if lockholder := metadata["lockholder"]; lockholder != "" { - opaqueMap["Lock-Holder"] = &typespb.OpaqueEntry{ - Decoder: "plain", - Value: []byte(lockholder), - } - } initRes, err := d.gateway.InitiateFileUpload(ctx, &provider.InitiateFileUploadRequest{ Ref: newRef, - LockId: metadata["lockid"], - Opaque: &typespb.Opaque{ - Map: opaqueMap, - }, - }) + LockId: metadata["lockid"]}) switch { case err != nil: return err @@ -431,6 +421,12 @@ func (d *driver) Upload(ctx context.Context, ref *provider.Reference, content io } httpReq.Header.Set(datagateway.TokenTransportHeader, token) + if lockid := metadata["lockid"]; lockid != "" { + httpReq.Header.Set(ocdav.HeaderLockID, lockid) + } + if lockholder := metadata["lockholder"]; lockholder != "" { + httpReq.Header.Set(ocdav.HeaderLockHolder, lockholder) + } httpRes, err := httpclient.New().Do(httpReq) if err != nil { diff --git a/pkg/rhttp/datatx/manager/simple/simple.go b/pkg/rhttp/datatx/manager/simple/simple.go index 8ce580e61a1..b1b489a6760 100644 --- a/pkg/rhttp/datatx/manager/simple/simple.go +++ b/pkg/rhttp/datatx/manager/simple/simple.go @@ -23,6 +23,7 @@ import ( "net/http" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/internal/http/services/owncloud/ocdav" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" "github.com/cs3org/reva/pkg/rhttp/datatx" @@ -76,6 +77,12 @@ func (m *manager) Handler(fs storage.FS) (http.Handler, error) { ref := &provider.Reference{Path: fn} metadata := map[string]string{} + if lockid := r.Header.Get(ocdav.HeaderLockID); lockid != "" { + metadata["lockid"] = lockid + } + if lockholder := r.Header.Get(ocdav.HeaderLockHolder); lockholder != "" { + metadata["lockholder"] = lockholder + } err := fs.Upload(ctx, ref, r.Body, metadata) switch v := err.(type) { diff --git a/pkg/rhttp/datatx/manager/spaces/spaces.go b/pkg/rhttp/datatx/manager/spaces/spaces.go index 03ce1cd7991..4f95b47f107 100644 --- a/pkg/rhttp/datatx/manager/spaces/spaces.go +++ b/pkg/rhttp/datatx/manager/spaces/spaces.go @@ -25,6 +25,7 @@ import ( "strings" provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" + "github.com/cs3org/reva/internal/http/services/owncloud/ocdav" "github.com/cs3org/reva/pkg/appctx" "github.com/cs3org/reva/pkg/errtypes" "github.com/cs3org/reva/pkg/rhttp/datatx" @@ -97,6 +98,12 @@ func (m *manager) Handler(fs storage.FS) (http.Handler, error) { Path: fn, } metadata := map[string]string{} + if lockid := r.Header.Get(ocdav.HeaderLockID); lockid != "" { + metadata["lockid"] = lockid + } + if lockholder := r.Header.Get(ocdav.HeaderLockHolder); lockholder != "" { + metadata["lockholder"] = lockholder + } err = fs.Upload(ctx, ref, r.Body, metadata) switch v := err.(type) {