Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix locks #4758

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-locking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Fix moving locked files, enable handling locked files via ocdav

We fixed a problem when trying to move locked files. We also enabled the ocdav service to handle locked files.

https://github.com/cs3org/reva/pull/4758
5 changes: 4 additions & 1 deletion internal/http/services/owncloud/ocdav/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ func (s *svc) handleDelete(ctx context.Context, w http.ResponseWriter, r *http.R
ctx, span := appctx.GetTracerProvider(r.Context()).Tracer(tracerName).Start(ctx, "delete")
defer span.End()

req := &provider.DeleteRequest{Ref: ref}
req := &provider.DeleteRequest{
Ref: ref,
LockId: requestLockToken(r),
}

// FIXME the lock token is part of the application level protocol, it should be part of the DeleteRequest message not the opaque
ih, ok := parseIfHeader(r.Header.Get(net.HeaderIf))
Expand Down
4 changes: 4 additions & 0 deletions internal/http/services/owncloud/ocdav/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,7 @@ func (s *svc) unlockReference(ctx context.Context, _ http.ResponseWriter, r *htt
}
return http.StatusInternalServerError, err
}

func requestLockToken(r *http.Request) string {
return strings.TrimSuffix(strings.TrimPrefix(r.Header.Get(net.HeaderLockToken), "<"), ">")
}
6 changes: 5 additions & 1 deletion internal/http/services/owncloud/ocdav/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ func (s *svc) handleMove(ctx context.Context, w http.ResponseWriter, r *http.Req
dst.Path = utils.MakeRelativePath(dstStatRes.GetInfo().GetName())
dst.ResourceId = dstStatRes.GetInfo().GetParentId()
}
mReq := &provider.MoveRequest{Source: src, Destination: dst}
mReq := &provider.MoveRequest{
Source: src,
Destination: dst,
LockId: requestLockToken(r),
}
mRes, err := client.Move(ctx, mReq)
if err != nil {
log.Error().Err(err).Msg("error sending move grpc request")
Expand Down
1 change: 1 addition & 0 deletions internal/http/services/owncloud/ocdav/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func (s *svc) handlePut(ctx context.Context, w http.ResponseWriter, r *http.Requ
uReq := &provider.InitiateFileUploadRequest{
Ref: ref,
Opaque: opaque,
LockId: requestLockToken(r),
}
if ifMatch := r.Header.Get(net.HeaderIfMatch); ifMatch != "" {
uReq.Options = &provider.InitiateFileUploadRequest_IfMatch{IfMatch: ifMatch}
Expand Down
11 changes: 11 additions & 0 deletions pkg/storage/fs/posix/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,17 @@ func (t *Tree) Move(ctx context.Context, oldNode *node.Node, newNode *node.Node)
return errors.Wrap(err, "Decomposedfs: could not move child")
}

// rename the lock (if it exists)
if _, err := os.Stat(oldNode.LockFilePath()); err == nil {
err = os.Rename(
filepath.Join(oldNode.ParentPath(), oldNode.Name+".lock"),
filepath.Join(newNode.ParentPath(), newNode.Name+".lock"),
)
if err != nil {
return errors.Wrap(err, "Decomposedfs: could not move lock")
}
}

// update the id cache
if newNode.ID == "" {
newNode.ID = oldNode.ID
Expand Down
5 changes: 0 additions & 5 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,6 @@ func (fs *Decomposedfs) Move(ctx context.Context, oldRef, newRef *provider.Refer
return err
}

// check lock on target
if err := newNode.CheckLock(ctx); err != nil {
return err
}

return fs.tp.Move(ctx, oldNode, newNode)
}

Expand Down
Loading