Skip to content

Commit

Permalink
Changed strategy following cs3apis#226
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Feb 14, 2024
1 parent fb2ad38 commit 2c6d9a9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
7 changes: 0 additions & 7 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,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"

Check failure on line 79 in internal/http/services/owncloud/ocdav/webdav.go

View workflow job for this annotation

GitHub Actions / lint

ST1003: const HeaderLockId should be HeaderLockID (stylecheck)
HeaderLockHolder = "X-Lock-Holder"
)

// WebDavHandler implements a dav endpoint.
Expand Down
21 changes: 7 additions & 14 deletions pkg/ocm/storage/outcoming/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,20 +399,7 @@ 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,
},
})
initRes, err := d.gateway.InitiateFileUpload(ctx, &provider.InitiateFileUploadRequest{Ref: newRef})
switch {
case err != nil:
return err
Expand All @@ -431,6 +418,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("X-Lock-Id", lockid)
}
if lockholder := metadata["lockholder"]; lockholder != "" {
httpReq.Header.Set("X-Lock-Holder", lockholder)
}

httpRes, err := httpclient.New().Do(httpReq)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/rhttp/datatx/manager/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,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("X-Lock-Id"); lockid != "" {
metadata["lockid"] = lockid
}
if lockholder := r.Header.Get("X-Lock-Holder"); lockholder != "" {
metadata["lockholder"] = lockholder
}

err := fs.Upload(ctx, ref, r.Body, metadata)
switch v := err.(type) {
Expand Down
6 changes: 6 additions & 0 deletions pkg/rhttp/datatx/manager/spaces/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ func (m *manager) Handler(fs storage.FS) (http.Handler, error) {
Path: fn,
}
metadata := map[string]string{}
if lockid := r.Header.Get("X-Lock-Id"); lockid != "" {
metadata["lockid"] = lockid
}
if lockholder := r.Header.Get("X-Lock-Holder"); lockholder != "" {
metadata["lockholder"] = lockholder
}

err = fs.Upload(ctx, ref, r.Body, metadata)
switch v := err.(type) {
Expand Down

0 comments on commit 2c6d9a9

Please sign in to comment.