Skip to content

Commit

Permalink
implement if-match check in storageprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Feb 22, 2022
1 parent 6e8cb77 commit 24c4944
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/storage-if-match.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add an if-match check to the storage provider

Implement a check for the if-match value in InitiateFileUpload to prevent overwrites of newer versions.

https://github.com/cs3org/reva/pull/2547
23 changes: 23 additions & 0 deletions internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,29 @@ func (s *service) InitiateFileUpload(ctx context.Context, req *provider.Initiate
}, nil
}

if ifMatch := req.GetIfMatch(); ifMatch != "" {
sRes, err := s.Stat(ctx, &provider.StatRequest{Ref: req.Ref})
if err != nil {
return nil, err
}

switch sRes.Status.Code {
case rpc.Code_CODE_OK:
if sRes.Info.Etag != req.GetIfMatch() {
return &provider.InitiateFileUploadResponse{
Status: status.NewFailedPrecondition(ctx, errors.New("etag doesn't match"), "etag doesn't match"),
}, nil
}
case rpc.Code_CODE_NOT_FOUND:
// Just continue with a normal upload
default:
return &provider.InitiateFileUploadResponse{
Status: sRes.Status,
}, nil
}

}

// FIXME these should be part of the InitiateFileUploadRequest object
if req.Opaque != nil {
if e, ok := req.Opaque.Map["lockid"]; ok && e.Decoder == "plain" {
Expand Down

0 comments on commit 24c4944

Please sign in to comment.