Skip to content

Commit

Permalink
port changes to refresh lock from edge branch
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Sep 29, 2022
1 parent d303fe9 commit 50be738
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 12 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/refresh-lock-improvements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Make Refresh Lock operation WOPI compliant

We now support the WOPI compliant `UnlockAndRelock` operation. This has been implemented in the Eos FS. To make use of it, we need a compatible WOPI server.

https://github.com/cs3org/reva/pull/3289
https://learn.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/rest/files/unlockandrelock
2 changes: 1 addition & 1 deletion internal/grpc/services/storageprovider/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ func (s *service) RefreshLock(ctx context.Context, req *provider.RefreshLockRequ
}, nil
}

if err = s.storage.RefreshLock(ctx, newRef, req.Lock); err != nil {
if err = s.storage.RefreshLock(ctx, newRef, req.Lock, req.ExistingLockId); err != nil {
var st *rpc.Status
switch err.(type) {
case errtypes.IsNotFound:
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fs/cback/cback.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (fs *cback) GetLock(ctx context.Context, ref *provider.Reference) (*provide
return nil, errtypes.NotSupported("Operation Not Permitted")
}

func (fs *cback) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error {
func (fs *cback) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock, existingLockID string) error {
return errtypes.NotSupported("Operation Not Permitted")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fs/nextcloud/nextcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ func (nc *StorageDriver) SetLock(ctx context.Context, ref *provider.Reference, l
}

// RefreshLock refreshes an existing lock on the given reference
func (nc *StorageDriver) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error {
func (nc *StorageDriver) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock, existingLockID string) error {
return errtypes.NotSupported("unimplemented")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fs/owncloud/owncloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ func (fs *ocfs) SetLock(ctx context.Context, ref *provider.Reference, lock *prov
}

// RefreshLock refreshes an existing lock on the given reference
func (fs *ocfs) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error {
func (fs *ocfs) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock, existingLockID string) error {
return errtypes.NotSupported("unimplemented")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fs/owncloudsql/owncloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ func (fs *owncloudsqlfs) SetLock(ctx context.Context, ref *provider.Reference, l
}

// RefreshLock refreshes an existing lock on the given reference
func (fs *owncloudsqlfs) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error {
func (fs *owncloudsqlfs) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock, existingLockID string) error {
return errtypes.NotSupported("unimplemented")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fs/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (fs *s3FS) SetLock(ctx context.Context, ref *provider.Reference, lock *prov
}

// RefreshLock refreshes an existing lock on the given reference
func (fs *s3FS) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error {
func (fs *s3FS) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock, existingLockID string) error {
return errtypes.NotSupported("unimplemented")
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type FS interface {
UnsetArbitraryMetadata(ctx context.Context, ref *provider.Reference, keys []string) error
SetLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error
GetLock(ctx context.Context, ref *provider.Reference) (*provider.Lock, error)
RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error
RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock, existingLockID string) error
Unlock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error
ListStorageSpaces(ctx context.Context, filter []*provider.ListStorageSpacesRequest_Filter) ([]*provider.StorageSpace, error)
CreateStorageSpace(ctx context.Context, req *provider.CreateStorageSpaceRequest) (*provider.CreateStorageSpaceResponse, error)
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func (fs *Decomposedfs) SetLock(ctx context.Context, ref *provider.Reference, lo
}

// RefreshLock refreshes an existing lock on the given reference
func (fs *Decomposedfs) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error {
func (fs *Decomposedfs) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock, existingLockID string) error {
return errtypes.NotSupported("unimplemented")
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,7 @@ func encodeLock(l *provider.Lock) (string, error) {
}

// RefreshLock refreshes an existing lock on the given reference
func (fs *eosfs) RefreshLock(ctx context.Context, ref *provider.Reference, newLock *provider.Lock) error {
// TODO (gdelmont): check if the new lock is already expired?

func (fs *eosfs) RefreshLock(ctx context.Context, ref *provider.Reference, newLock *provider.Lock, existingLockID string) error {
if newLock.Type == provider.LockType_LOCK_TYPE_SHARED {
return errtypes.NotSupported("shared lock not yet implemented")
}
Expand All @@ -897,6 +895,10 @@ func (fs *eosfs) RefreshLock(ctx context.Context, ref *provider.Reference, newLo
return errtypes.BadRequest("caller does not hold the lock")
}

if existingLockID != "" && oldLock.LockId != existingLockID {
return errtypes.BadRequest("mismatching existing lock id")
}

path, err := fs.resolve(ctx, ref)
if err != nil {
return errors.Wrap(err, "eosfs: error resolving reference")
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/localfs/localfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func (fs *localfs) SetLock(ctx context.Context, ref *provider.Reference, lock *p
}

// RefreshLock refreshes an existing lock on the given reference
func (fs *localfs) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock) error {
func (fs *localfs) RefreshLock(ctx context.Context, ref *provider.Reference, lock *provider.Lock, existingLockID string) error {
return errtypes.NotSupported("unimplemented")
}

Expand Down

0 comments on commit 50be738

Please sign in to comment.