Skip to content

Commit

Permalink
Changed strategy following cs3org/cs3apis#226
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Apr 15, 2024
1 parent 9b25b07 commit 2130d0c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 29 deletions.
9 changes: 0 additions & 9 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
13 changes: 6 additions & 7 deletions internal/http/services/owncloud/ocdav/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion internal/http/services/owncloud/ocdav/webdav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 8 additions & 12 deletions pkg/ocm/storage/outcoming/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/rhttp/datatx/manager/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/rhttp/datatx/manager/spaces/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2130d0c

Please sign in to comment.