diff --git a/pkg/storage/utils/decomposedfs/node/locks.go b/pkg/storage/utils/decomposedfs/node/locks.go index eee9e67a2da..e4aefd731f1 100644 --- a/pkg/storage/utils/decomposedfs/node/locks.go +++ b/pkg/storage/utils/decomposedfs/node/locks.go @@ -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" @@ -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") } diff --git a/pkg/storage/utils/decomposedfs/node/locks_test.go b/pkg/storage/utils/decomposedfs/node/locks_test.go index 08ca26f87c8..5cd4dd0ad5e 100644 --- a/pkg/storage/utils/decomposedfs/node/locks_test.go +++ b/pkg/storage/utils/decomposedfs/node/locks_test.go @@ -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", @@ -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() {