Skip to content

Commit

Permalink
fix lock tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Feb 17, 2022
1 parent 6d58569 commit 63c0dc9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions pkg/storage/utils/decomposedfs/node/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"encoding/json"
"os"
"path/filepath"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
Expand All @@ -34,20 +35,22 @@ import (

// SetLock sets a lock on the node
func (n *Node) SetLock(ctx context.Context, lock *provider.Lock) error {
nodepath := n.LockFilePath()
// check existing lock
if l, _ := n.ReadLock(ctx); l != nil {
lockID, _ := ctxpkg.ContextGetLockID(ctx)
if l.LockId != lockID {
return errtypes.Locked(l.LockId)
}
err := os.Remove(n.LockFilePath())
err := os.Remove(nodepath)
if err != nil {
return err
}
}

os.MkdirAll(filepath.Dir(nodepath), 0700)
// O_EXCL to make open fail when the file already exists
f, err := os.OpenFile(n.LockFilePath(), os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0600)
f, err := os.OpenFile(nodepath, os.O_EXCL|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return errors.Wrap(err, "Decomposedfs: could not create lock file")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/utils/decomposedfs/node/locks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("Node locks", func() {
otherUser = &userpb.User{
Id: &userpb.UserId{
Idp: "idp",
OpaqueId: "foo",
OpaqueId: "otheruserid",
Type: userpb.UserType_USER_TYPE_PRIMARY,
},
Username: "foo",
Expand All @@ -68,8 +68,8 @@ var _ = Describe("Node locks", func() {
User: env.Owner.Id,
LockId: uuid.New().String(),
}
n = node.New("spaceid", "tobelockedid", "", "tobelocked", 10, "", env.Owner.Id, env.Lookup)
n2 = node.New("spaceid", "neverlockedid", "", "neverlocked", 10, "", env.Owner.Id, env.Lookup)
n = node.New("u-s-e-r-id", "tobelockedid", "", "tobelocked", 10, "", env.Owner.Id, env.Lookup)
n2 = node.New("u-s-e-r-id", "neverlockedid", "", "neverlocked", 10, "", env.Owner.Id, env.Lookup)
})

AfterEach(func() {
Expand Down

0 comments on commit 63c0dc9

Please sign in to comment.